0

When I need to search for either "regulatory" or "regulatories" I use

\bregulatory\b|\bregulatories\b

Is there any way I could create a Regex considering the word beginning as same and just consider the different ends "y" OR "ies" but not any other. I mean, I could use:

\bregulator.{0,3}\b

but it could mismatch regulatorial

So, I am looking for something like that: \bregulator.{y OR ies}\b (it doesn't exist in Regex and it is exactly how to translate it to regex what I am looking for).

Many thanks,

Cadu

2 Answers2

1

a Regex considering the word beginning as same and just consider the different ends "y" OR "ies" but not any other

Please, try with this pattern:

\bregulator(?:y|ies)\b
  • The (?:y|ies) statement to exactly what you expect. So (?:A|B) means A or B.
aliteralmind
  • 18,274
  • 16
  • 66
  • 102
Caio Oliveira
  • 1,139
  • 11
  • 22
0

You can try:

\bregulator(?:y|ies)\b

Update based on your comment:

\bregulator(?:y|ies|s)\b

http://regex101.com/r/gJ6nD4

Pedro Lobito
  • 75,541
  • 25
  • 200
  • 222
  • `?:` is just a [non-capturing group](http://www.regular-expressions.info/brackets.html) - it's not necessary here. – Simon MᶜKenzie Apr 25 '14 at 01:33
  • Thanks everybody! An additional point. If it was just an "s" in the end of a word, which could exists or not. E.g. regulator|regulators. Often I use regulator.? but if I know it can be only "s", I would like to consider it could have or not a character after regulator, if there is it can be only "s". – carloscadux Apr 25 '14 at 02:01
  • Thanks again! I know the very basic regex. The ?: is new for me. For what is it? I used the expression without it (y|ies|s) and the output where the same. So, what are the advantages of ?: thanks – carloscadux Apr 25 '14 at 13:00
  • 1
    ?: means that group won't be captured and the regex will perform faster, also less confusion on the output. – Pedro Lobito Apr 25 '14 at 13:18