-1

I'm searching inside an html code a specific string starting or containing, for example "name:" with this:

$r = '/name.*/';
preg_match_all($r,$body, $matches, PREG_SET_ORDER);

But I can find "name" in at least 3 different languages, so, is it possible to create this pattern with three options instead of searching 3 times? something like "or"? (regex is under PHP)

HamZa
  • 14,671
  • 11
  • 54
  • 75
Mark
  • 684
  • 2
  • 9
  • 25
  • 1
    there: http://stackoverflow.com/questions/4743329/php-regex-or-operator use the OR operator to match multiple cases. – briosheje Oct 17 '13 at 09:59
  • aaaaaaaaaaaaaaaaah!!! THANKS! so it should be something like: $pattern= 'patternA|patternB'; – Mark Oct 17 '13 at 10:04
  • Yes `$r = '/name1|name2|name3/';` should work. – anubhava Oct 17 '13 at 10:08
  • Yup, both solutions proposed here and in the comment below actually works. Feel free to use the one you like the most, even though defining a pattern like Steve Chambers did is probably the way you should take :) – briosheje Oct 17 '13 at 16:49

1 Answers1

1

To reiterate what was said in the comments in an answer (so this doesn't appear as unanswered in searches) + including parentheses (to allow the wildcard to be added once at the end):

Assuming the names are "name1", "name2" and "name3", change your $r definition to:

$r = '/(name1|name2|name3).*/';
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208