RegExp for removing text between parenthesis

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colossus

    RegExp for removing text between parenthesis

    Hi,

    I have a string like this:
    GeboGebo Wiki 0.9.2 (Default branch)

    I want to remove the words between the parenthesis. I tried this regexp:
    /\([a-zA-Z0-9]\)/ but without success, what is wrong with it ?

    Thank you,
    --
    Colossus

    Cpsed, a Linux OpenGL 3D scene editor
    Compare the best free open source 3D Modeling Software at SourceForge. Free, secure and fast 3D Modeling Software downloads from the largest Open Source applications and software directory

  • Markku Uttula

    #2
    Re: RegExp for removing text between parenthesis

    Colossus wrote:[color=blue]
    > I have a string like this:
    > GeboGebo Wiki 0.9.2 (Default branch)
    >
    > I want to remove the words between the parenthesis. I tried this
    > regexp: /\([a-zA-Z0-9]\)/ but without success, what is wrong with it
    > ?[/color]

    You're looking for *exactly one* character a-z or 0-9.

    RegExp /\([a-z0-9\ ]+\)/ might work a bit better. Though, it takes the
    parenthesis with the contents, and I don't know if that's the wanted
    behaviour (you said you wanted to remove the *text* between
    parenthesis).

    --
    Markku Uttula

    Comment

    • Colossus

      #3
      Re: RegExp for removing text between parenthesis

      Markku Uttula wrote:
      [color=blue]
      > RegExp /\([a-z0-9\ ]+\)/ might work a bit better. Though, it takes the
      > parenthesis with the contents, and I don't know if that's the wanted
      > behaviour (you said you wanted to remove the *text* between parenthesis).[/color]

      Thank you, i should also remove the parenthesis. How to do ?
      --
      Colossus

      Cpsed, a Linux OpenGL 3D scene editor
      Compare the best free open source 3D Modeling Software at SourceForge. Free, secure and fast 3D Modeling Software downloads from the largest Open Source applications and software directory

      Comment

      • John Dunlop

        #4
        Re: RegExp for removing text between parenthesis

        Colossus wrote:
        [color=blue]
        > I have a string like this:
        > GeboGebo Wiki 0.9.2 (Default branch)
        >
        > I want to remove the words between the parenthesis.[/color]

        If your string is, as you say, like that, why not use the
        string functions instead?

        substr($subject ,0,strpos($subj ect,'('))
        [color=blue]
        > I tried this regexp:
        > /\([a-zA-Z0-9]\)/ but without success, what is wrong with it ?[/color]

        Your character class doesn't allow spaces and only matches a
        single character and the surrounding brackets.

        `\([a-z ]+\)`i

        --
        Jock

        Comment

        • Colossus

          #5
          Re: RegExp for removing text between parenthesis

          John Dunlop wrote:
          [color=blue]
          > Your character class doesn't allow spaces and only matches a
          > single character and the surrounding brackets.
          > `\([a-z ]+\)`i[/color]

          Thank you, it works ! I don't know php; can the substr be used as a
          replacement of the regexp `\([a-z ]+\)`i ? Which is faster ?
          --
          Colossus

          Cpsed, a Linux OpenGL 3D scene editor
          Compare the best free open source 3D Modeling Software at SourceForge. Free, secure and fast 3D Modeling Software downloads from the largest Open Source applications and software directory

          Comment

          • John Dunlop

            #6
            Re: RegExp for removing text between parenthesis

            Colossus wrote:
            [color=blue]
            > can the substr be used as a replacement of the regexp `\([a-z ]+\)`i ?[/color]

            The regular expression matches letters and spaces and the
            surrounding brackets, whereas the substr returns everything
            up to the first '('. The equivalence of their output
            depends on your subject string.
            [color=blue]
            > Which is faster ?[/color]

            I don't know. Can you tell me?

            --
            Jock

            Comment

            Working...