Merge multiple regex in Java -


i have written regex omit characters after first occurrence of characters (, , #)

string number = "(123) (456) (7890)#123"; number = number.replaceall("[,#](.*)", ""); //this 1st regex 

then second regex numbers (remove spaces , other non numeric characters)

number = number.replaceall("[^0-9]+", ""); //this 2nd regex 

output: 1234567890

how can merge 2 regex 1 piping o/p first regex second.

so need remove symbols other digits , whole rest of string after first hash symbol or comma.

you cannot concatenate patterns |operator because 1 of patterns anchored implicitly @ end of string.

you need remove symbols digits , hashes commas first since tegex engine processes string left right , can add alternative match comma or hash text after them. use dotall modifier in case have newline symbols in input.

use

 (?s)[,#].*$|[^#,0-9]+ 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -