I want to replace a String which contains of placeholders which should only consists on digit.
For ex - this is the test string {0} with correct placeholder {1}.
Valid placeholders - {digits}
Invalid Placeholders - alphanumeric, empty, digit with whitespace, character with whitespace
Can anyone help me with a regex. I tried this but its not working -
\{((([^0-9]).+?)|(.([^0-9])+?))\}
Thank in advance!
You can use
\{(?!\d+\})[^{}]*\}
See the regex demo
Details
\\{
- a {
char (?!\\d+\\})
- a negative lookahead that fails the match if there are 1 or more digits and then a }
char immediately to the right of the current location [^{}]*
- 0 or more chars other than {
and }
\\}
- a }
char.
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.