- Where Developers Learn, Share, & Build Careers


I am trying to match the full word from some lines, want to know how to use or in regex For example, if I only have one keyword, it works fine, example

  regex = ". * \\ b" + "KEYWORD1" + "\\ b. *"; String Reggae = ". * \\ b" + "KEYWORD1 | KEYWORD2 | KEYWORD3" + "\\ b. *"; For (int i = start; i  end; i ++) {if (line [i] .i (regex)) {System.out.println ("match"); }}    

you want:

  string Regex = ". * \\ b (KEYWORD1 | KEYWORD2 | KEYWORD3) \\ b. *";   

Basically, your regex was evaluated in this way:

 . * \ BKEYWORD1 | KEYWORD2 | KEYWORD3 \ b. *   

But you want to:

 . * \ B (KEYWORD1 | KEYWORD2 | KEYWORD3) \ b. *   

This cooler can help you to analyze the regexes and find such bugs.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -