I'm trying to extract a single word from a line of text. As I understand it, Powershell regexes are almost the same as PCREs (and I have a way of easily testing PCREs). I have a file containing (amongst other things) something like...
ignore=thisline
username=symcbean
dontRead=thisEither
And I want to get the value associated with "username".
I know that the LHS of '=' will contain "username", optionally surrounded by whitespace, and the RHS will contain the value I am trying to extract (optionally surrounded by whitespace). The string I am looking for will match \w+, hence:
(?<=username=)\w+
works for the case without additional whitespace. But I can't seem to accommodate the optional white space. For brevity I've only shown the case of trying to handle a whitespace before the '=' below:
(?<=username\s*=)\w+ - doesn't match with or without additional space
(?<=username\W+)\w+ - doesn't match with or without additional space
(?<=username[\s=]*)\w+ - doesn't match with or without additional space
However in each case above, the group in the look-behind zero-width assertion (/username\s*=/, /username\W+/, /username[\s=]*/) matches the relevant part of the string.
I'm hoping to get a single value match (rather than array).