Questions tagged [character-class]

Character classes are regular expression constructs that defines and matches from a list of meta- and literal characters. Use [regex-negation] for questions related to complementing character classes in regex.

Character classes are regular expression constructs that defines and matches from a list of meta-characters and literal characters in .

Read more:

99 questions
0
votes
1 answer

Matching opposite of [[:blank:]] character class in sed

I cannot find a way to represent the inverse of a character class in sed. If this were a perl-like environment I would use [^\s]. However in sed this appears to match non-s, not non-whitespace. On a line of text (from gdrive) I need to capture the…
billmill
  • 331
  • 1
  • 3
  • 14
0
votes
1 answer

Cannot remove a specific diacritical mark

I'm trying to remove all diacritical marks from a string during a validation (for more background, see below). In order to do that, I'm using the following code: private static String stripAccents(final String s) { if(s == null) { return…
Michaël Vreux
  • 316
  • 1
  • 2
  • 14
0
votes
1 answer

Javascript - Create Regex Character Class

Is there a way to use javascript's regex engine to create a character class that matches with " or " (one space before ") or . or , or [SM_l] or nothing (not the string "nothing" , just 0 characters) Background Context: This is going…
Foobar
  • 7,458
  • 16
  • 81
  • 161
0
votes
1 answer

Match input starting with non-number or empty string followed by specific pattern

I'm using Java regular expressions to match and capture a string such as: 0::10000 A solution would be: (0::\d{1,8}) However, the match would succeed for the input 10::10000 As well, which is wrong. Therefore, I now have: \[^\d\](0::\d{1,8}) Which…
Dave L.
  • 9,595
  • 7
  • 43
  • 69
0
votes
1 answer

Character class vs. Lookaround - matching non-existing character at the end of a word.

q[^x] – matches “qu” in “question”. It does not match “Iraq” since there is no character after the “q” for the negated character class to match. q(?!u) matches “q” in “Iraq” but not in “question”. (This is a negative lookahead). The “there is no…
user9098366
0
votes
0 answers

Understanding tuple output from groups() method after re.match()

I am working with regular expressions and am struggling to understand a particular output. Case 1: >>> m = re.match("(abc)+", "abc") >>> m.groups() ('abc',) Case 2: >>> m = re.match("([abc])+", "abc") >>> m.groups() ('c',) In Case 1 above, I do…
Nabeel M.
  • 25
  • 1
  • 8
0
votes
6 answers

What special meaning do square braces have in a regular expression?

Can anyone explain me this code split("[ ]+", $s); thanks $s = "Split this sentence by spaces"; $words = split("[ ]+", $s); print_r($words); Output: Array ( [0] => Split [1] => this [2] => sentence [3] => by [4] => spaces )
user514310
0
votes
2 answers

isdigit() isn't working in a simple program?

#include #include #include void main() { clrscr(); int a; cout<<"Enter a digit"; cin>>a; if(isdigit(a)) { cout<<"You have entered a digit"; } else { cout<<"Not a…
program_g21
  • 21
  • 1
  • 5
0
votes
2 answers

How to represent an empty character class in Java regex

I want to create a character class that doesn't match any character. For now, I have been representing the pattern like this: Pattern p = Pattern.compile("[a&&b]"); or even Pattern p = Patterncompile("[^\\x{0}-\\x{10FFFF}]"); Is there a proper way…
randombee
  • 699
  • 1
  • 5
  • 26
0
votes
1 answer

How can I inverse a regex expression to use it in java replaceAll method?

I need a last alphabetic character of string example: ABRACADABRA123456. The regex expression [a-zA-Z](?=\d+) give me the match in all my cases. How can I change (inverse) the expression to use it in java method e.g.:…
0
votes
1 answer

Regular expression - issue with [,-?[0-9]+]* pattern

This is my pattern: ^~[0-9]+@Y 1,710,-?[0-9]+[,-?[0-9]+]*\n$ For some reason it's match :~01@Y 1,710,9, But not: ~01@Y 1,710,9 I don't understand why it's need the last comma? http://regex101.com/r/kP4pZ2/1
cheziHoyzer
  • 4,803
  • 12
  • 54
  • 81
0
votes
1 answer

python: square backet in character class

I'm trying to match square brackets (using character class) in python. But the following code is not successful. Does anybody know what is the correct way to do? #!/usr/bin/env python import re prog = re.compile('[\[]+') print…
user1424739
  • 11,937
  • 17
  • 63
  • 152
0
votes
1 answer

Some hostings don't like character class in .htaccess regex?

I have this problem very rarely and only on some hostings. Here is my .htaccess for my custom framework: Options -Indexes ErrorDocument 403 /application/views/403.htm ErrorDocument 404 /application/views/404.htm RewriteEngine on RewriteRule…
Mladen Janjetovic
  • 13,844
  • 8
  • 72
  • 82
0
votes
1 answer

php preg_match using shorthand and character class combined

echo preg_match( '/\d[A-Z]/', 'CD' ); // Displays “0” How can it display 0 when clearly there are characters that match the range "[A-Z]"? Is it the way the parsing occurs?
Robert
  • 10,126
  • 19
  • 78
  • 130
0
votes
1 answer

Groovy Regex: What does a tilde in a character class do?

I've got this Regex that comes out of a groovy code: (?:[^\p{Alnum}äöü**~D~V~\~_**]|^) (?:sometext|s\.t\.) (?:[^\p{Alnum}äöü**~D~V~\~_**]|$$) The only thing I do not understand is this part: **~D~V~\~_** What doas the tilde do in there? Is that…
barigorokarl
  • 3
  • 1
  • 4