Skip to content
Advertisement

Regex to find text between string pattren

String: [img border=0]/scm/images/bbcode/sets/misc/bullet_go.png[/img]

Result I Want: [img border=0]images/bbcode/sets/misc/bullet_go.png[/img] without /scm/ text.

Issue: Text scm is not static, could be any other text in data.

What I want: Have a look to this string
[img border=0]/scm/images/bbcode/sets/misc/bullet_go.png[/img]
Regex which can fetch a text between ] and images/bbcode/ so the regex will detect the scm text and then can remove this scm from String data and end result will look like [img border=0]images/bbcode/sets/misc/bullet_go.png[/img]

PS: I am implementing this logic in Java.

Advertisement

Answer

I have captured text between ‘] and /images..’ and replace this text with “”. Check the following demo:

String s = "[img border=0]/scm/images/bbcode/sets/misc/bullet_go.png[/img]";
s = s.replaceAll("(?<=])/[^/]+/","");
System.out.println(s);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement