Forums Register Login

Regex to split string on condition

+Pie Number of slices to send: Send
Hi, It would be good if someone can help me with a regex problem am facing.

I need to compare two types of strings.

Type1 : This type of string has several substrings in it enclosed within '{$' and '$}'.
Example:
My name is {$Jill$}. I work on {$Java$} development.

Type2 : This type of string has several substrings in it enclosed within '#{' and '}'.
Example:
My name is #{Jack}. I work on #{C++} development.

When comparing string of type1 with string of type2, I want to ignore the substrings within {$...$} in type1 and those within #{...} in type2, and then compare. In the above example, ignoring the substrings within those specified characters and then comparing would yield that they are equal strings. This is the comparison that I want to do. Can you please guide hoe to do it in regex?

For type1, I tried this:
Pattern pattern = Pattern.compile("\\{.*\\}");
pattern.split(stringType1);

But this doesn't seem to work. Kindly guide.

Thanks.
+Pie Number of slices to send: Send
<please ignore/>
+Pie Number of slices to send: Send
"Priya India", please check your private messages regarding an important administrative matter.
+Pie Number of slices to send: Send
Something like that could be a starting point:
+Pie Number of slices to send: Send
Yes, James. Both would be the same under my requirement.

Thanks, Peter. I'll try this now.
+Pie Number of slices to send: Send
 

Priya India wrote:Yes, James. Both would be the same under my requirement.



I withdrew my response because I realised there was much much more to the problem than I originally thought. If the two strings I provide truly were to be considered the same then you don't want to split the lines. You just want to remove the {$ ... $} and #{ ... } elements and then compare the resulting strings.
+Pie Number of slices to send: Send
 

Devaka Cooray wrote:"Priya India", please check your private messages regarding an important administrative matter.


"Priya India", I really suggest you follow these instructions.
+Pie Number of slices to send: Send
Am sorry for not noticing the msg on the private msg. I took note of it. Thanks.

Peter, Thanks so much! It works!
+Pie Number of slices to send: Send
It's just a starting point (it doesn't cover all possible characters) ... just to make sure you understand ; - )
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2738 times.
Similar Threads
MVC, JSP/Servlet/Bean Design Issue
file upload problem
Design Mental Roadblock
finding the value of a radio button
jsf - dataTable with external filter
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:26:15.