0

I'm finding that learning RegEx is nearly impossible, since every tool or helper site offers the worst explanations and doesn't cover everything. I'm attempting to work through the puzzles on regexcrossword.com and they don't offer substantial help and/or insight. This is causing confusion.

Here is what I understand:

  1. [^SPEAK] = not S, P, E, A, K
  2. + = matches one or more of the previous characters
  3. Therefore [^SPEAK]+ = nothing

I don't understand how this is supposed to work. What am I missing?

B.Foor
  • 21
  • 8
  • 1
    regex101.com explains the regexp pretty well. – Barmar Sep 17 '19 at 18:02
  • One or more of a character not S, P, E, A, or K. Ex: FOO would match because it doesn't contain any of those letters. Where are you confused? – dvo Sep 17 '19 at 18:02

2 Answers2

0

[^SPEAK] matches any character that isn't one of those 5 letters. + means to match the preceding pattern at least 1 time. So [^SPEAK]+ matches a sequence of characters that isn't in that set.

For example, if the input is 123ABCDEFG, it will match 123, BCD and FG.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I'm not able to grasp the logic used here. How can one match a preceding pattern, if that pattern isn't allowed? – B.Foor Sep 17 '19 at 18:10
  • `G` matches the pattern `[^SPEAK]`, because it's not one of those characters. – Barmar Sep 17 '19 at 18:11
  • And `FG` is a sequence of 2 characters in a row that match the pattern, so they're grouped together with `+`. – Barmar Sep 17 '19 at 18:18
  • Have you tried reading the tutorial at regular-expressions.info – Barmar Sep 17 '19 at 18:18
  • yes. Their pages are so text heavy that it makes my head spin. Most of the time, I can't find what I'm looking for on that site or others, so i come here to ask questions. – B.Foor Sep 17 '19 at 18:36
0

[^SPEAK] means apart from S,P,E,A,K take any character and + means one or more time So It will accept any character taken one or more time which s not in the list [SPEAK]

ssssssss is valid string aaaa is valid string SA is invalid string

Vicky Kumar
  • 1,358
  • 1
  • 14
  • 26