RE: [NTS] How to search a QUESTION MARK in a regular expression
- I use this all the time to find ends of sentences:
It could also be done using classes (which don't need escapes except for a few items):
RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/
From: firstname.lastname@example.org [mailto:email@example.com] On Behalf Of Robert Bull
Sent: Wednesday, October 10, 2012 07:02
Subject: Re: [NTS] How to search a QUESTION MARK in a regular expression
Wednesday, October 10, 2012, 2:00:55 AM, EB wrote:
E> / ?fred(.*)p=31 did not work as a search string in FIND.
I think John's right to suggest trying "\?". In regular expressions,
"?" is a metacharacter that means the character to its left may or may
not be present. Quoting The AWK Programming Language, "(r)? matches
the null string or any string matched by r ..." Ergo, you probably
need to "escape" a "?" with a backslash in front of it.
[Non-text portions of this message have been removed]
- As is so often the case, I overlooked the obvious. I thought I had tried pretty much everything - but apparently not. The \ seems to work. THANK YOU!
--- In firstname.lastname@example.org, "John Shotsky" <jshotsky@...> wrote:
> RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/
> From: email@example.com [mailto:firstname.lastname@example.org] On Behalf Of EB
> Sent: Tuesday, October 09, 2012 18:01
> To: email@example.com
> Subject: [NTS] How to search a QUESTION MARK in a regular expression
> I have a bunch of lines in a file that look something like this:
> I want to strip everything to the right of and including the QUESTION MARK using a regular expression
> / ?fred(.*)p=31 did not work as a search string in FIND.
> It did work if I removed the question mark - but that left the question mark in place after the REPLACE.
> I can - turning the regular expression block off - FIND/REPLACE the question mark with a less tricky character and then
> run (with RegEx on) the FIND/REPLACE to get rid of everything to the right of and including the new character - but that
> is additional steps.
> Is there a way to identify the question mark as a question mark instead of special character within the original RegEx
> FIND/REPLACE? (The [:?:] construct did not seem to work.)
> Thank you.
> [Non-text portions of this message have been removed]
- --- In firstname.lastname@example.org, Robert Bull <barlennan@...> wrote:
>Why "probably"? It's a PCRE rule, and John is undoubtedly right. See "Backslash" in the Help on Regex:
> Ergo, you probably need to "escape" a "?" with a backslash
> in front of it.
> If (the backslash) is followed by a character that is not aAn alternative is to search the '?' in hex '\x3F' or octal '\077'.
> number or a letter, it takes away any special meaning that
> character may have. This use of backslash as an escape character
> applies both inside and outside character classes.