Extract only characters from string

So i have scraped some data to data table that looks like this
“picker-1
95 package”

how I can extract only the “picker-1”?

p.s the “95 package” are in the new line but one row

1 Like

Hey @Fauzan_Marantama,

You can use string.split function after reading that data from a cell.

Split by either Environment.Newline or spaces which gives you the array of words separated by the spaces or newline.

Access the first element is the array which gives you the output.

Thanks :slight_smile:

@Fauzan_Marantama
we can use Regex in case of we want to ensure some value content presence.

E.g. picker is fixed, number can be different:
grafik

or another pattern
grafik

1 Like

@Nithinkrishna
thank you for the answer, is there any coding example?

@ppr
sorry, the image doesnt load at all, can you change the image source link?

@Fauzan_Marantama
another try for image:

patterns:

picker-\d+

^.*-\d+\r?$

@ppr
still error, i think there is problem with the domain (500 origin error)

\

and if the picker name are based on the name, e.g
“fauzanpicker
0 package”
can it extract only the fauzanpicker? already tried newline split, but the result is still the full text

so lets change the pattern to and give a try:

^.*\r?$

for working with regex have a look here:

However it is recommended that you will collect of text variations and share the set with us. Based on this we can work out the most close matching solution approach. Here we want just check if regex or

YourStringVar.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries)(0)

will better match to your case

1 Like

thank you, marked as solutions

this is c# code sample.

my conditions is that

  1. ‘picker’ must is before ‘-’.
  2. one number digit must be at end.

reference below.

string pattern = @"\w+-\d";
string src = @"picker-1
95 package";
MatchCollection matches = Regex.Matches(src,pattern);
string[] arr = matches.Cast < Match >().Select(m => m.Value).ToArray();
Console.WriteLine(string.Join(",",arr));

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