简体   繁体   中英

regular expressions checking two strings

Hi wonder if anyone can help - I'm trying to check for occurance of one of two possible strings using regex - but my knowlege of regex is very limited, so I'm not having much sucess.

I'm trying to look for 'Email' and 'eMailConfirm', this is what I have so far and is working for Email

subject is the id of a input field, so it could be 'name','Email','eMailConfirm'

$subject = $getPromoOuter['label'];
$pattern = '/^Email/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 0);

I tried a number of potential expressions to try and incorporate the second string but I can't seem to get it to play (plus a few guesswork ones based on others)

any idea how I can concatenate those two strings and check for an occurance of either?

Thanks for looking

I'll just place an answer here, as I do think I have a good idea what your requirement is.

Your current regex is /^Email/ which matches any string which starts with 'Email'. (whether or not it has to start with it is unclear to me).

In case you need to match either Email or eMailConfirm, not at the start of the string, you should go for

/Email|eMailConfirm/

If the matches do need to be at the front of the string, just prepend both with a '^' character: /^Email|^eMailConfirm/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM