regex - regular expression match case sensitive off -
i have regular expression finds 2 words in line.
the problem is case sensitive. need edit matches both case.
reqular expression
^(.*?(\bpain\b).*?(\bfever\b)[^$]*)$
you can use regexoptions.ignorecase
set case insensitive matching mode. way make the entire pattern case insensitive. same effect can achieved (?i)
inline option @ beginning of pattern:
(?i)^(.*?(\bpain\b).*?(\bfever\b)[^$]*)$
you can use inline flag set case insensitive mode part of pattern:
^(.*?(\b(?i:pain)\b).*?(\b(?i:fever)\b)[^$]*)$
or can match "pain" or "pain" with
^(.*?(\b(?i:p)ain\b).*?(\bfever\b)[^$]*)$
another alternative using character classes [pp]
, etc.
note not have set capturing group round whole pattern, have access via rx.match(str).groups(0).value
.
^.*?(\b[pp]ain\b).*?(\b[ff]ever\b)[^$]*$
Comments
Post a Comment