Welcome to openkapow Sign in | Join
.

Re: [How to?] Extract a substring from the text stored in an attibute?

  •  02-28-2007, 9:19 PM

    Re: [How to?] Extract a substring from the text stored in an attibute?

    Thank-you, your answer helps a lot.

    My problem is the following: if a string has a left bracket, then keep everything before the bracket, else keep the whole string.
    Example:
    text1 text2 (text_to_discard) -> text1 text2
    text1 text2 -> text1 text2

    I could not find how to do this with regex only, but managed to do it doing the following:
    Use a "If Then" converter
    If (.*)\(.*
    then $1
    else $0

    Explanation (for regex illiterate people like me): 
    (.*) means any text, the brackets mean "group": if the pattern matches, then this group will be returned
    \( means the left bracket (the back slash is necessary because "(" is a special character)
    .*  means any text after the left bracket

    In the If/then converter, if the pattern matches, then $1 refers to the (.*) part, the text before the left bracket.
    If the text has no left bracket, then nothing matches, and $0 refers to the original string.

    Maybe there is a way to do this just with a regex and not with the if / then converter. Please let me know.

    Filed under: ,
View Complete Thread
.
Copyright 2006, 2007 KapowTech.com All Rights Reserved Company | Contact | Terms | Privacy