Loading ...
Sorry, an error occurred while loading the content.

Re: [NTS] How to search a QUESTION MARK in a regular expression

Expand Messages
  • Robert Bull
    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
    Message 1 of 6 , Oct 10, 2012
    View Source
    • 0 Attachment
      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.

      --
      Regards,

      Robert Bull
      mailto:barlennan@...
    • John Shotsky
      I use this all the time to find ends of sentences: ( .| ?|!)( R| x20| )| ) It could also be done using classes (which don t need escapes except for a few
      Message 2 of 6 , Oct 10, 2012
      View Source
      • 0 Attachment
        I use this all the time to find ends of sentences:
        (\.|\?|!)(\R|\x20|\)|\")
        It could also be done using classes (which don't need escapes except for a few items):
        [?.!]+[")\x20]+

        Regards,
        John
        RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

        From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of Robert Bull
        Sent: Wednesday, October 10, 2012 07:02
        To: EB
        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.

        --
        Regards,

        Robert Bull
        mailto:barlennan@... <mailto:barlennan%40yahoo.co.uk>



        [Non-text portions of this message have been removed]
      • EB
        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!
        Message 3 of 6 , Oct 10, 2012
        View Source
        • 0 Attachment
          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 ntb-scripts@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
          >
          > \?
          >
          > Regards,
          > John
          > RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/
          >
          > From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of EB
          > Sent: Tuesday, October 09, 2012 18:01
          > To: ntb-scripts@yahoogroups.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:
          >
          > Ga53t76lah/Z3vdeg14/V0c2/?freds=OTvvA4OfhbfjI6MQ,0,0,0,&p=31
          >
          > 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]
          >
        • flo.gehrke
          ... An alternative is to search the ? in hex x3F or octal 077 . Regards, Flo
          Message 4 of 6 , Oct 10, 2012
          View Source
          • 0 Attachment
            --- In ntb-scripts@yahoogroups.com, Robert Bull <barlennan@...> wrote:
            >
            > Ergo, you probably need to "escape" a "?" with a backslash
            > in front of it.

            Why "probably"? It's a PCRE rule, and John is undoubtedly right. See "Backslash" in the Help on Regex:

            > If (the backslash) is followed by a character that is not a
            > 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.

            An alternative is to search the '?' in hex '\x3F' or octal '\077'.

            Regards,
            Flo
          Your message has been successfully submitted and would be delivered to recipients shortly.