I need to remove all strings from my text file, such as:
flickr:user=32jdisffs
flickr:user=acssd
flickr:user=asddsa89
I'm currently using fields[i] = fields[i].replaceAll(" , flickr:user=.*", "");
however the issue with this is approach is that any word after flickr:user=
is removed from the content, even after the space.
thanks
Going by the question as stated, chances are that you want:
This will match the string, including the value of
user
up to but not including the first space, followed by a space, and replace it either by a blank string, or a single space. However this will (barring the comma) net you an empty result with the input you showed. Is that really what you want?I'm also not sure where the
" , "
at the beginning fits into the example you showed.The reason for your difficulties is that an unbounded
.*
will match everything from that point up until the end of the input (even if that amounts to nothing; that's what the*
is for). For a line-based regular expression parser, that's to the end of the line.flickr:user=\w+
should do it:Reference:
\w
= A word character:[a-zA-Z_0-9]
You probably need
replaceAll("flickr:user=[0-9A-Za-z]+", "");