I am trying to solve an issue that is a by product of a Mysql error - thestring item looks like this:
`9839 mysql: [Warning] Using a password on the command line interface can be insecure. mysql: [Warning] Using a password on the command line interface can be insecure.
I want t strip off everything from the first space after the digits (which change) to the right
This regex works on regex101
but I thinkI need to include the whoe string in the criteria and Im not sure how to do that
Indeed where you are defining this regex matters. But to answer you question assuming you are using the REGEX transformation add-on in openHAB, yes, the expression needs to map the whole String and the first matching group (i.e. the stuff that matches the pattern in the first ( )) is what get’s returned.
So your expression should be something like:
You might need to use \s instead of a literal space.
Basically, the only difference is that, as Rich said, the OH regex expression has to also match the entire string as well as having a capture group. In practice this means that either the start or the end (or both) of your regex needs to have a .*. In this case, I would simplify this regex even further and just use:
This will capture all numerical digits at the start of the string, and then as soon as it finds a non-numerical digit (i.e., the space) it exits the capture and just matches the rest of the string to satisfy the OH regex requirement.
Regex always works one character at a time. When there is a list or a range in brackets that means “match any one character from the set in the brackets”. So [0-9] will match any one numeral. You want more than one numeral, you want 4. The * is the symbol that means “match as many instances of the preceding character as you can”. So, [0-9]* matches nothing but numeral character and continues to do so until the first character that’s not a numeral. When the expression can’t match [0-9]* any more then it moves on to the next part of the expression which is .*. The dot (period) means “match ANY character at all”. So .* means “match as many instances of any character as you can” which, of course, is the remainder of the string.