I'm trying to do this: I have this kind of text (i.e. a file):
[[dadasd sadasd sdsd ad asddd]] [[dasdsd]] dsdsd [[dsdas]] ... [[dd ssas dd]]
I want only the sentences between double square brackets. How can I solve this with java?
//This one is not working:
String patternStr = "(.*)\\[\\[(.*)\\]\\](.*)";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher("");
// Set the input
matcher.reset("[[sdasd]] ddd [[ddssssssssssss]] vvvddd [[dd]] asdasda [[asdsa]] ");
...
Thanks in advance
You want the following regex:
\[\[(.+?)\]\]
which then translates to a Java string as:
\\[\\[(.+?)\\]\\]
PowerShell test:
PS Home:\> [regex]::Matches("[[sdasd]] ddd [[ddssssssssssss]] vvvddd [[dd]] asdasda [[asdsa]] ", '\[\[(.+?)\]\]') | ft -auto
Groups Success Captures Index Length Value
------ ------- -------- ----- ------ -----
{[[sdasd]], sdasd} True {[[sdasd]]} 0 9 [[sdasd]]
{[[ddssssssssssss]], ddssssssssssss} True {[[ddssssssssssss]]} 14 18 [[ddssssssssssss]]
{[[dd]], dd} True {[[dd]]} 40 6 [[dd]]
{[[asdsa]], asdsa} True {[[asdsa]]} 55 9 [[asdsa]]
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