Pardon my novelty in java, I have the following string ( Below ), I am trying to clean it and extract only the integer digits
. What would be the correct java regex to use to achieve my goal:
Original String : uint32_t Count "77 (0x0000004D)"
Desired Output: 77
I have tried reading Java docs on regex but I only got more confused. I guess EE engineers are not cut for this fancy coding tricks :D
You could exploit "\\b"
which is a word boundary:
String regex = "\\b\\d+\\b";
Matcher m = Pattern.compile(regex).matcher("uint32_t Count \"77 (0x0000004D)\"");
m.find();
System.out.println(m.group()); //output 77
"\\d+"
finds a substring of digits, and surrounding it with "\\b"
ensures that it is not embedded in another word/symbol.
more examples to get a pattern helps but with what you have given i can think of a simple regex that matches the group with the given pattern and then you strip out the quote and get your integer.
(["](\d{1,}))
I would suggest you play around regex more over here so you learn as you practice
User contributions licensed under CC BY-SA 3.0