Skip to main content
Solved

how to define beginning and end of text


terezia86
Forum|alt.badge.img

Hi, I would like to know hot to define the texts beginnig and end.

I have got :

 

Attribute: Adressen_kalkuliert_drop_loc

 

D-L-143245-143245-F-45--1xMICRO-DUCT-12x10-6MM

D-F-422-F-471--1xMICRO-DUCT-12x10-6MM

(a tousands of them)

 

and need to define Attribute Value:

 

L-143245 (from the first one) and

F-422 (from the second one)

 

the texts are always different, and have a different number of numbers

But beginns alway with "F", or "L" and ends always with "-" behind the number.

 

thanks

 

Best answer by redgeographics

You can try a StringSearcher with the regular expression [L|F]-\\d+ but on both lines of sample text it will actually match more than just that. If you create a list of matches and grab the first item it will probably be what you want.

For more security, try the regular expression ^D-[L|F]-\\d+ and then a StringReplacer afterwards to replace regex ^D- with nothing.

View original
Did this help you find an answer to your question?

4 replies

redgeographics
Celebrity
Forum|alt.badge.img+48
  • Celebrity
  • Best Answer
  • May 3, 2019

You can try a StringSearcher with the regular expression [L|F]-\\d+ but on both lines of sample text it will actually match more than just that. If you create a list of matches and grab the first item it will probably be what you want.

For more security, try the regular expression ^D-[L|F]-\\d+ and then a StringReplacer afterwards to replace regex ^D- with nothing.


terezia86
Forum|alt.badge.img
  • Author
  • May 3, 2019
redgeographics wrote:

You can try a StringSearcher with the regular expression [L|F]-\\d+ but on both lines of sample text it will actually match more than just that. If you create a list of matches and grab the first item it will probably be what you want.

For more security, try the regular expression ^D-[L|F]-\\d+ and then a StringReplacer afterwards to replace regex ^D- with nothing.

Perfekt! It worked great!

Thanks a lot


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • May 3, 2019
redgeographics wrote:

You can try a StringSearcher with the regular expression [L|F]-\d+ but on both lines of sample text it will actually match more than just that. If you create a list of matches and grab the first item it will probably be what you want.

For more security, try the regular expression ^D-[L|F]-\d+ and then a StringReplacer afterwards to replace regex ^D- with nothing.

A small correction. [L|F] matches not only L or F but also | (pipe), so this expression would be better.

[LF]-\d+
or
(L|F)-\d+

redgeographics
Celebrity
Forum|alt.badge.img+48
takashi wrote:

A small correction. [L|F] matches not only L or F but also | (pipe), so this expression would be better.

[LF]-\d+
or
(L|F)-\d+

Thanks for catching that, I *thought* I knew a bit about regexes... 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings