Skip to content
Advertisement

Python Regex to Java

I am trying to convert a python regex to java. It finds a match in python but fails on the same string in java.

Python regex : "(CommandLineEventConsumer)(x00x00)(.*?)(x00)(.*?)({})(x00x00)?([^x00]*)?".format(event_consumer_name)

Java regex : "(CommandLineEventConsumer)(\u0000\u0000)(.*?)(\u0000)(.*?)(" + event_consumer_name + ")(\u0000\u0000)?([^\u0000]*)?"

I also tried this : "(CommandLineEventConsumer)(\x00\x00)(.*?)(\x00)(.*?)(" + event_consumer_name + ")(\x00\x00)?([^\x00]*)?"

What I’m I missing please?

I have attached a piece of the code

JavaScript

UPDATE

In python the groups return

python result screenshot

Advertisement

Answer

From what I posted as comments: The (CommandLineEventConsumer)(u0000u0000)(.*?)(u0000)(.*?) part matches fine.
group(3) gets cscript KernCap.vbs
group(4) gets a null character
but group(5) gets nothing.

I did try in Python and I have the exact same lack of match when I include the (BVTConsumer). So you probably had a difference in the code doing the matching in Python, not the regex itself.

So the reason is that you have a n in your string so the matching stops there. If you do

JavaScript

it does match in your example.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement