如何只允许正则表达式中的组

时间:2017-01-19 19:30:41

标签: php regex

我无法搜索此问题

我想要正则表达式,我可以允许一组字符所以我想允许字符a到z和package GamePackage; import java.awt.*; import java.awt.geom.Rectangle2D; import java.util.Random; public class Square { public int XLocation; public int Size; public int YLocation = -Size; public int fallSpeed = 1; Random rand = new Random(); int R = rand.nextInt((256-40)+1)+40; int G = rand.nextInt((256-40)+1)+40; int B= rand.nextInt((256-40)+1)+40; Color RandomColour = new Color (R, G, B); public int generateRandomXLocation(){ return XLocation = rand.nextInt(Game.WINDOW_WIDTH - Size); } /* //creates a random value and stores it in squareWidth */ public int generateRandomSquareSize(){ return Size = rand.nextInt((30-17)+1)+17; } public int generateRandomFallSpeed(){ return fallSpeed = rand.ints(3, 3, 8).findFirst().getAsInt(); // 3, 3, 8 } /* //paints the square with the variables generated in the random methods */ public void paint(Graphics g){ g.setColor(RandomColour); g.fillRect(XLocation,YLocation,Size,Size); } /* //sets the squareWidth and square fallSpeed to a random value for every square created */ public Square(){ generateRandomXLocation(); generateRandomSquareSize(); generateRandomFallSpeed(); } public void update(){ //changes the squares xLocation and fallSpeed if the created square reaches the bottom of the screen if(YLocation >= Game.WINDOW_HEIGHT){ generateRandomXLocation(); generateRandomFallSpeed(); generateRandomSquareSize(); YLocation = -Size; } //moves the square down if the square is inside the window if(YLocation <= Game.WINDOW_HEIGHT){ YLocation += fallSpeed; } } public Rectangle GetBounds(){ Rectangle rectangle = new Rectangle(XLocation,YLocation,Size,Size); return rectangle; } } 作为一个组我不想允许&nbsp;和{{1单独但仅作为组

我试过

&

但这不起作用,有人可以提供帮助

1 个答案:

答案 0 :(得分:2)

字符类中的所有字符都是单个字符。所以:

using UnityEngine;
using UnityEngine.UI;

[AddComponentMenu("UI/CodeText", 10)]
public class CodeText : Text
{
    void Awake() {
        Game.Instance.trackMe();
    }
}

允许

(&nbsp;) (&nbsp

;有一些例外;范围all characters,领先a-z,用于反转使用情况,元字符^ ......以及其他几个字符。

您可以使用字符类和更改来允许空间实体。

\n

如果您想允许更多实体,您可以在实体方面进行更多更改。

([a-z]|&nbsp;)+

这是一个regex101演示:https://regex101.com/r/1FB2bJ/1