2

I'm rubbish at reg ex's anyway and been trying all day with no success.

input string:

"fred XY-C4569-32 (Bloggs) 24 acacia (revision 1) road"

I just want to extract

"fred XY-C4569-32"

fred may be shorter or longer e.g. (ted or william) so i cant just sub string in on an index to do it.

I have been trying stuff like

-replace "^([a-z0-9 -]*) ([a-z0-9 \\(\\) -])" , '$1'

but no joy so far

thanks

1
  • Try the stuff like -replace "^(\S+\s+\S+).*" , '$1'. Commented Jul 2, 2015 at 13:51

1 Answer 1

2

Almost there, just add + or * next to the second character class.

-replace "^([A-Za-z0-9 -]*\\b) [A-Za-z0-9() -]+" , '$1'

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

That worked Thanks for that. Any idea why the $1 now gives me "fred XY-C4569-32." with a "." now on the end?
Its Ok I got it now, I had a . on the end of my string I forgot to put in my orig post.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.