Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expression question

Tags:

java

string

regex

I want to replace the question mark (?) in a string with some other words. What is the regular expression for question mark. For example, I want to replace question mark in "word=?" to something else, say "stackoverflow". Then the result would be "word=stackoverflow". What is the syntax in java?

like image 658
Progress Programmer Avatar asked Nov 29 '22 20:11

Progress Programmer


1 Answers

string.replaceFirst("\\?", yourWord)

That will replace the first occurrence of a '?' in your code with whatever yourWord is.

If you want to replace every '?' with yourWord then use string.replaceAll("\\?", yourWord).

See the javadocs for more info.

like image 60
jjnguy Avatar answered Dec 06 '22 08:12

jjnguy