Isolate a portion of a string with repeated character

Hello!
I saw a few topics around string manipulation, but I got lost, and did not find a good clean solution so far.
I need to manage a string where the format is:

AAAA_BBBB_information+extra
mystring = AAAA_BBBB_information+extra

(note: the actual string uses a “asterisk” before extra, but the edit of this chat make it messy with BOLD characters, so i’ve substituted with a plus sign.)

I want to isolate “information
I found a workaround, but it looks overcomplicated to me.
Any suggestion? here below what I have

1- removing the extra seemed reasonably easy (extra is a repetitive info, so i use mystring.replace(“extra",“”).replace("”,“”) <<-- yes the “*” is not removed from the 1st replace…
2- Removing AAAA_BBBB_ is a challenge. I’m doing a sequence of ‘indexof’ then substring that dose not seem that nice

a=mystring
aa=a.IndexOf(“_”)
aaa=a.Substring(aa)
aaaa=aaa.Substring(1)

b = aaaa
bb=b.IndexOf(“_”)
bbb=b.Substring(bb)
bbbb=bbb.Substring(1)

c = bbbb.replace(“*RpaExc”,“”).replace(“Rpa",“”).replace("”,“”)

information =c

Just use RegEx.

System.Text.RegularExpressions.RegEx.Match(inputstring,"(?<=AAAA_BBBB_)(.*)(?=\*extra)")

image

Also, when writing posts or replying, just use the </> button at the top (with text highlighted) to have it not interpret code.

1 Like

EDITED: incorporated * on end+extra, Thanks to Paul

give a try at:
grafik

(.)\1+_(.)\2+_\*(.*)(?=\*)

and refer to group
grafik

But maybe a simple pattern also will work
grafik

use </> Format button from editor

1 Like

Thx to all the replies.
I’m close but not done completely.

Here’s a test string that will probably clarify what I need to achieve.
I need to chop away after the 2nd “_”; I want to retain “Information_Difficult

TEST_test33_Information_Difficult*Extratoremove

Opposite to the examples, I’m not splitting after the 1st “_”
I did some trials, but no success so far!
image

Hi,

How about the following pattern?

(?<=^[^_]+_[^_]+_)[^\*]+

image

Regards,

1 Like

sample differs from orgin use case description, as there are no repeating chars (told at the begin)
Lets refer to @Steven_McKeering SOP

and for the basics

Example:
grafik

Reminder

1 Like

Hello

SOP is always gives you the best reply from the community (cheers @ppr) - What if there are three, four or five words (instead of one or two)???

There will be better ways but give this one a try in the meantime:
image

works perfectly! Thank you!

1 Like

Hi again @avaccaro ,

An additional option for a dynamic length string which only relies only on the underscores and the asterisk. Lets remove the unwanted text rather than match the text we need.

You will need to use a regex replace by inserting the below into an ‘Assign’ activity:
System.Text.RegularExpressions.Regex.Replace(youStr, “(?<=\*).*|^[^_\n\r]+_[^_\n\r]+_”, “”)

Examples - noting the highlighted text will be removed
1 word:
image
2 words:
image
3 words:
image

Cheers

Steve

That’s great! thank you!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.