I want to replace any content in my text file in between symbols < and >
What's the regular expression to accept any symbol ? I've currently:
fields[i] = fields[i].replaceAll("\\<[a-z0-9_-]*\\>", "");
But it works only for letters and numbers, if there is a symbol in between < and >, the string is not replaced.
thanks
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" .
Throw in an * (asterisk), and it will match everything. Read more. \s (whitespace metacharacter) will match any whitespace character (space; tab; line break; ...), and \S (opposite of \s ) will match anything that is not a whitespace character.
It's a negative lookahead, which means that for the expression to match, the part within (?!...) must not match. In this case the regex matches http:// only when it is not followed by the current host name (roughly, see Thilo's comment).
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9. (a-z0-9) -- Explicit capture of a-z0-9 .
To accept any symbol, .* should do the trick
Try this [^\>]*
(any character that isn't >
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With