Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match "any character" in regular expression?

Tags:

java

regex

The following should be matched:

AAA123 ABCDEFGH123 XXXX123 

can I do: ".*123" ?

like image 625
Saobi Avatar asked May 26 '10 12:05

Saobi


People also ask

How do I match a character in regex?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).

How do you match a char?

Use square brackets [] to match any characters in a set. Use \w to match any single alphanumeric character: 0-9 , a-z , A-Z , and _ (underscore). Use \d to match any single digit. Use \s to match any single whitespace character.

Which regex will match any character but a B or C?

[abc] : matches a, b, or c. [a-z] : matches every character between a and z (in Unicode code point order). [^abc] : matches anything except a, b, or c.

How do you match a word in regex?

To run a “whole words only” search using a regular expression, simply place the word between two word boundaries, as we did with ‹ \bcat\b ›. The first ‹ \b › requires the ‹ c › to occur at the very start of the string, or after a nonword character.


1 Answers

Yes, you can. That should work.

  • . = any char except newline
  • \. = the actual dot character
  • .? = .{0,1} = match any char except newline zero or one times
  • .* = .{0,} = match any char except newline zero or more times
  • .+ = .{1,} = match any char except newline one or more times
like image 115
Delan Azabani Avatar answered Sep 30 '22 05:09

Delan Azabani