Help RegularExpressions.Regex

Hi,

I need a subject, sometimes Extral, sometimes something else.

This my Code

System.Text.RegularExpressions.Regex.Matches(Currentitem.Subject.toString,“(?<=LCM-)(.)(:)(?=Extral)”)(0).ToString.Replace(" “,”")

Hi @punnipah

Can you share the sample Input and expected output?

the sample
Memo number STO 00835/2022(1) Subject LCM-C Extralxxxxx
Memo number STO 00835/2022(1) Subject LCM-C Starxxxxx

expected output
LCM-C Extral
LCM-C Star

HI @punnipah

How about this following?

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=Subject\s)\S.*(?=x{5})").Tostring

image

Regards
Gokul

1 Like

Sorry I might misunderstand you.

I want the C value in the middle.

Ahead is LCM-behind is Extral Or Star

HI @punnipah

Check out this expression?

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=LCM\W)\S.*(?=\sExtral|\sStar)").Tostring

image

1 Like

If there is no Extral or Star next time, will it work?
I can’t say that I’ll always have these two words.

Every time it will be a Single Letter? @punnipah

Like C

try this @punnipah

(LCM-C [A-Za-z]+)

e.g. input is
Memo number STO 00835/2022(1) Subject LCM-C Extral

output of
System.Text.RegularExpressions.Regex.Match(Currentitem.Subject.toString,"(LCM-C [A-Za-z]+)").Groups(1).Value
is
LCM-C Extral

1 Like

Not Single Letter

image

Try with this : (?<=LCM\W)\S.*(?= |\sExtral|\sStar)

@punnipah

1 Like


need C value

Or Next :LCM-A Extral ,LCM-B Extral

Hi @punnipah

Try this one : (?<=LCM\W)\S.*(?=\sExtral|\sStar)|(?<=LCM\W)\S.*

image

1 Like

Thank you So much ^^

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