-1

I'm having trouble figuring out what exactly this regex pattern is searching for mostly due to the number at the end. From what I can tell, it is saying search for any character that is not a-z and repeat it for the whole string. What does the 3 do?

   [^a-z.+3]

Thanks!

user3002486
  • 421
  • 1
  • 7
  • 18
  • 2
    `3` is just a literal. It matches char "3". – Łukasz Rogalski Aug 04 '16 at 15:32
  • It's really only half a question. Beyond the simple technical details of what a character class is, without seeing how it's used, it's really only _half a question_. If you re-label the question I'd up-vote it. –  Aug 04 '16 at 15:57

4 Answers4

5

In a character class all characters loose their special meaning (if any), only the first ^ is used to negate the class, - is used to define a range (except at the first and last position), an eventual backslash may start an escape sequence and ] closes the class.

3 is the literal character 3, + is the literal character +, . is a literal ., nothing more.

[^a-z.+3] matches one character that isn't in this list and is the same as [^.a-z3+] or [^+.a-z3]

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
2

[^a-z.+3] match characters other than a-z . + and 3

lets take an example,

x = 'stack overflow... 363 is amazing++useful'

lets take each element in regex one by one.

[^a-z] matches characters other than a-z

In [19]: re.findall(r'[^a-z]', x)
Out[19]: [' ', '.', '.', '.', ' ', '3', '6', '3', ' ', ' ', '+', '+']

[^a-z.] matches characters other than a-z and .

In [20]: re.findall(r'[^a-z.]', x)
Out[20]: [' ', ' ', '3', '6', '3', ' ', ' ', '+', '+']

[^a-z.+] matches characters other than a-z . +

In [21]: re.findall(r'[^a-z.+]', x)
Out[21]: [' ', ' ', '3', '6', '3', ' ', ' ']

[^a-z.+3] matches characters other than a-z . + 3

In [22]: re.findall(r'[^a-z.+3]', x)
Out[22]: [' ', ' ', '6', ' ', ' ']
Ganesh_
  • 569
  • 7
  • 10
1

It searches anything not in lowercase a-z, dot, plus sign and number 3 Try here. Paste in your regex pattern

xbb
  • 2,073
  • 1
  • 19
  • 34
0
[^a-z.+3]

[^a-z.+3] match a single character not present in the list below

a-z a single character in the range between a and z (case sensitive)

.+3 a single character in the list .+3 literally

from : https://regex101.com/r/wI5hG2/1

So in one line this match a caracter different of a to z and . and + and 3

baddger964
  • 1,199
  • 9
  • 18