简体   繁体   中英

Using Java RegEx, how do I compare a variable with another variable, while ignoring quotes and white space?

I have two variables. Variable 1 is in the format

"          35" 

while variable 2 is just

35

How would I compare these two?

You can just use:

var1.replaceAll("\\W+", "").equals( var2.replaceAll("\\W+", "") )

Here replaceAll("\\\\W+", "") will remove all non-word characters from both variables before comparing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM