Can I use a cell to form part (only) of a regex?

In a reply to another question @mikekaganski seemed to show a REGEX function that uses a cell for a condition(?)

My regex is for extracting a street address from a long string of many address items:
REGEX(W2,"([:digit:]+[:print:][:digit:]*) "&"[:print:]*"&"\b(ROAD|RD|STREET|ST|LANE|LN)\b")

I need a much longer list of possible road name parts than the six items (ROAD…LN) there.

I want to store these in a named cell elsewhere (concatenated with the pipes).

Can this be done? If so, what is the syntax, please?

Thanks for all help.

for extensive token list, also keep an eye on VLOOKUP

re+lookup.ods (9.6 KB)

Thank you. You’ll have to excuse me, as a noob: what is a “token list”?

(I think, but am not sure, that your solution is working from the other end to my problem? I have an address string such as
GROUND FLOOR 123 ROSE HILL LANE CANNOCK CHASE BIRMINGHAM
and need to extract the street address “123 Rose Hill Lane”

sorry for the jargon (Lexical analysis - Wikipedia)

indeed the list can be long :

1 Like

Hallo
Assuming C11 has the text:
GROUND FLOOR 123 ROSE HILL LANE CANNOCK CHASE BIRMINGHAM

=REGEX(C11 ; "(?i)(\d+.*?(" & TEXTJOIN("|";1;$G$2:$G$10) & "))" )

returns: 123 ROSE HILL LANE

1 Like

indeed works at ground floor,
but already fails at 1st floor :wink:

1 Like

…but not on »second floor« :slightly_smiling_face:

Of course! I have never claimed that a universal solution can be found in this way! :innocent:

but already fails at 1st floor :wink:

Yeah, I found similar.

I’m getting around that by separating all references to floors before I process it - which I need anyway

TEXTJOIN function

1 Like

Thank you - that’s a powerful function I didn’t know!

I still don’t know the syntax. I think I want =REGEX(A1,namedCell), but this doesn’t seem to work.

Using TEXTJOIN and “&”, namedCell returns
\b(road|rd|street|st|lane|ln)\b

but =REGEX(A1,namedCell) returns #N/A

EDIT: reason is that regex is case sensitive, and my data is in UPPER. Off I go to find how to do case-insensitive regex
EDIT2: This help page says in Options you can toggle Match case. I have nothing called Options on a Mac? But in Preferences > Calc > Calculate > General calcuations , the “Case sensitive” box is unchecked.
Any tips?

Details_specific_to_REGEX_function
e.g. =REGEX("test","(?i)"& "TEST")

1 Like

Thank you! What does & do, if you have time?

just normal concatenation.
same as =REGEX("test","(?i)TEST")

1 Like

the REGEX-function works mostly independend of any setting in…

1 Like