RegExp Help

PennController for IBEX Forums Support RegExp Help

This topic contains 2 replies, has 2 voices, and was last updated by Avatar samsanto 4 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6059
    Avatar
    samsanto
    Participant

    Hi Jeremy,

    I am trying to check if user input contains at least one of two possible words (from a csv), and I am having trouble coming up with the correct syntax for the RegExp. I’ve tried so many different ways of writing it, but I can’t get it. Here’s what I have that is the closest to it… but it only works if the first word (option1) is found, the second one (option2) is ignored completely.

    Any help would be appreciated!

    
    getButton("cont")
                .wait(
                    getTextInput("desc")
                        .testNot.text("").failure(getText("warning").print())
                        .and(
                            getTextInput("desc").test.text(new RegExp(variable.Option1) || new RegExp(variable.Option2))
                                .failure( getText("warning").print() )
                        )
                )
            ,
    
    

    Thanks so much,
    Sam

    #6060
    Jeremy
    Jeremy
    Keymaster

    Hi Sam,

    You cannot use the || operator inside a PennController test command like that. The TextInput text test command accepts either a string or a regex as its argument—what you’re doing here is passing the first non-null disjunct, which will necessarily be new RegExp(variable.Option1) because this constructor will never return null (or undefined, etc).

    Long story short, you want to build a single regex object that will match both Option1 and Option2, like this: new RegExp(variable.Option1+"|"+variable.Option2)

    Jeremy

    #6062
    Avatar
    samsanto
    Participant

    perfect! Thanks Jeremy.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.