Replacement with Regular expressions in Java - I have a String
allof{
condition {licenseState=="NY"}
condition{professionId==301}
condition {professionId=="301"}
}
would be it's possible to do a replacement in java using regex so the string looks like this one:
allof{
condition 'licenseState=="NY"', {licenseState=="NY"}
condition 'professionId==301', {professionId==301}
condition 'professionId=="301"', {professionId=="301"}
}
basically getting what inside the {} brackets and putting it separately. Is it possible and how? NewLine char is not guaranteed to be present after each condition.
I've tried:
condition\s*?{[a-zA-Z0-9=<>\s"']*}
Maroun
96.4k30 gold badges195 silver badges249 bronze badges
2 Answers 2
You can use the string replaceAll function. Something like this:
yourString.replaceAll("\\{([^{}]*\\=\\=[^{}]*)\\}", "'1ドル', {1ドル}");
answered Mar 29, 2013 at 18:53
Mike Dinescu
56k17 gold badges124 silver badges153 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Assuming no nested {}
str = str.replaceAll( "(?<=condition)\\s*(\\{([^}]+)\\})", " '2ドル', 1ドル" );
answered Mar 29, 2013 at 18:58
MikeM
13.8k3 gold badges38 silver badges49 bronze badges
Comments
lang-java
codecondition\s*?{[a-zA-Z0-9=<>\s"']*}codewhich selected everything, but I don't know how to extract inner part of it{([^}]*)