Quantcast
Channel: How do we remove special characters from a string from a particular position in java? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Wiktor Stribiżew for How do we remove special characters from a string from a particular position in java?

$
0
0

You can use

inputString.replaceAll("(\\G(?!^)|name=\")([^\"\\p{Punct}]*)\\p{Punct}(?=[^\"]*\")", "$1$2")

See the regex demo

The regex matches

  • (\G(?!^)|name=\") - Group 1: name=" or the end of the preceding successful match
  • ([^\"\p{Punct}]*) - Group 2: any zero or more chars other than " and punctuation chars
  • \p{Punct} - any punctuation chars
  • (?=[^\"]*\") - immediately from the current position to the right, there must be any zero or more chars other than " and then a " char.

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>