Absent Member.
Absent Member.
1021 views

Blank token question

Jump to solution

For example.

I have a simple regex.

(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)

If last token ((.*) is blank then message cannot be parsed. How I can solved this problem?

Labels (2)
Tags (2)
0 Likes
1 Solution

Accepted Solutions
Absent Member.
Absent Member.

In your last token, instead of just (.*) change it to (.*|) 


This would effectively capture either a value or null to which either way when you tokenize it, it might be semantically null if the token is empty. From then on, you can use some built in functions to do additional validation/checking if needed. HTH.

View solution in original post

0 Likes
8 Replies
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

Mikhail -

You must be mistaken.  If your last token is (.*) all that means is that greadly takes any data from the row after the last expression such as (\S+).

(\S+) means grab every character number or letter all the way up to the next whitespace no matter UPPER CASE or lower case.

(.*) which says match anthing from this point forward and stick it into a variable.

In order to stick the data from the expression (.*) you need to define/map where you want it to go and the data type known as a token ...

e.g. -

token[N].name=sSub

token[N].type=String

Then  you may want to define where it needs to go .. known as a event...

e.g.

event.name=sSub

You may want to look at the Flex Connector developer guide - https://protect724.hp.com/servlet/JiveServlet/downloadBody/2280-102-13-14516/FlexConn_DevGuideConfig.pdf

Further, if you do not want to deal with the rest of the rubbish (this is why you may use the (.*) you need do no more than assign it a token and then it will drop from getting parsed into a field.

scotty

0 Likes
Absent Member.
Absent Member.

Sometimes in message I can have text after (\S+) which I would like to parse by regex (.*) and sometime  I can haven't this text.

In scenario when I haven't text I see in logs:

Message [text text text text anytext Any] did not match the common regular expression [(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)], ignoring...

0 Likes
Absent Member.
Absent Member.

In config I have line:

contains.empty.tokens=true

0 Likes
Knowledge Partner Knowledge Partner
Knowledge Partner

Hi,

try this


(\S+) (\S+) (\S+) (\S+) (\S+) (\S+)(.*)


no space between the last 2 token.



PS: Remember to mark answer as helpfull or correct if this solve your problem.


------------------------------------
Please use the Like button below, if you find this post useful or mark it as an accepted solution if it resolves your issue.
0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

In addition to contains.empty.tokens=true, you might need a question mark for the last token in your regex.  I can't remember off the top of my head exactly where it should go, but something like below might work. 

(\S+) (\S+) (\S+) (\S+) (\S+) (\S+)?(.*)

0 Likes
Absent Member.
Absent Member.

Thanks, i try but it not help.

0 Likes
Absent Member.
Absent Member.

In your last token, instead of just (.*) change it to (.*|) 


This would effectively capture either a value or null to which either way when you tokenize it, it might be semantically null if the token is empty. From then on, you can use some built in functions to do additional validation/checking if needed. HTH.

View solution in original post

0 Likes
Absent Member.
Absent Member.

Thanks its helped.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.