# Extract the name of a point with Regular Expression

I have a list of points as strings in the form

{"A1=(345.2345,3423.1)","B=(2123,97.123)","KX=(2144.546,-4455)"}


and I would like to extract the names using RegularExpression. For a single point I tried

StringCases["A1=(345.2345,3423.1)", RegularExpression["^.+\\="]]


but the output is

{"A1="}


How can I extract only the name (everything that is on the left of "=" at the beginning of the string) without the character "=" itself?

• A slight variant of the solution already given: StringCases[lst, RegularExpression["(^.+)[=]"]:>"$1"] where 'lst=your_list Mar 18, 2020 at 9:43 • In addition, maybe consider StringSplit[lst, "="][[All,1]] or StringSplit[lst, RegularExpression["="]][[All,1]] Mar 18, 2020 at 11:05 ## 3 Answers ClearAll[f] f = StringCases[RegularExpression["(^.+)="] :> "$1"]

f /@ {"A1=(345.2345,3423.1)",  "B=(2123,97.123)", "KX=(2144.546,-4455)"}


{{"A1"}, {"B"}, {"KX"}}

ClearAll[f]
f = StringCases[RegularExpression["^[^=]+(?==)"]];

f /@ {"A1=(345.2345,3423.1)", "B=(2123,97.123)", "KX=(2144.546,-4455)"}

{{"A1"}, {"B"}, {"KX"}}


Another way, without using regular expressions

StringSplit[#, "="] & /* First /@ {"A1=(345.2345,3423.1)", "B=(2123,97.123)", "KX=(2144.546,-4455)"}

{* {"A1", "B", "KX"} *)