ICU Regex (iOS) vs. PCRE RegEx (Desktop) issues

Hey all,

Need some RegEx wisdom here. I have a bunch of regular expressions in my desktop app that I am porting over to an iOS app. In the desktop, these all work great. They also work great in Kem’s RegExRx application. I generally take the text I am scanning and put that in RegExRx and build the expression there until I get what I want. I then copy and paste the code. It works great.

On the iOS side of things, I am using Jason King’s JKRegEx classes. But everything is failing. Not getting any matches. I’ve talked to Jason and he says perhaps it’s a difference between the ICU engine that iOS uses and the PCRE engine that the desktop uses. I’m not an expert, so I thought I’d post here and see if anyone can tell what I am doing wrong. So here is an example expression and the text I am parsing. Please don’t make fun of my expressions! :slight_smile:

([A-Z]\\x20?((?:\\d{1,2}\\.)){2}(?:\\d{1,2}).*?)([\\R/])

Text Being Searched:

Mon, 03 Feb 2020 15:55:57 -0500 27483045 214164 u-boot_c.bin 4060803258 3155808 uuImage 1044641709 13946880 initrd2m B2.0.3 /usr/local/bin #

Now this is one example. I am trying to pull out the “B2.0.3” in this case. But I want to pull anything after it as well until I get to the new line and the forward slash. This value is a firmware version of a product. Sometimes there is text after the last digit that is part of the firmware build so I want to capture that as well.

On desktop and in RegExRX, this is capture 100% of the time. In iOS with Jason’s classes, it fails.

I have worked backwards in iOS, and I have success up to the .*? part of the expression. So:

([A-Z]\\x20?((?:\\d{1,2}\\.)){2}(?:\\d{1,2}))

Works fine. Captures the B2.0.3 but wouldn’t capture any text after it. So something breaks here and I don’t know what. And this is just one expression. I’ve probably got 10 or 15 more that also aren’t working.

I’m kinda stuck on this so any help would be much appreciated…

Oh and yes, before you ask about why I have the optional space character after the first Alpha character in the expression, there are some firmware versions where there’s a space there… :slight_smile:

Yes, there are differences that make Apple’s regular expression engine less capable. I’m afraid you’re going to have to look those up and adjust accordingly. Or use a PCRE plugin, of such a thing exists.

iOS - no plugins
Although I suppose he could build a pcre dylib and then expose it using declares in his app - but - blech !

[quote=478690:@Norman Palardy]iOS - no plugins
Although I suppose he could build a pcre dylib and then expose it using declares in his app - but - blech ![/quote]
Yeah, no. I am not that skilled in this sort of thing.

I just want something that works and follows the rules! Seems like putting .*? in the middle of an expression works in PCRE but not in ICU. Trying to figure out a different way of specifying: Give me any character from where I am at now to the end of line and a /.

Haven’t tested, but try:

[^\\r\
]*

In the past on Windows, i used RegExBuddy/RegExMagic which is able to convert between different RegEx Flavours. If you have a Windows OS Machine, maybe?

http://www.regexbuddy.com/convert.html

[quote=478694:@Sascha S]In the past on Windows, i used RegExBuddy/RegExMagic which is able to convert between different RegEx Flavours. If you have a Windows OS Machine, maybe?

http://www.regexbuddy.com/convert.html[/quote]
I’d have to look into that perhaps…

But that looks to be between different languages. Does it show differences between engines and would it as a windows platform even have the iOS ICU engine?

Hope this helps http://userguide.icu-project.org/strings/regexp

Yeah, while it is a great resource and explains things well, it doesn’t completely help because:

.*?

Should be a valid search item according to the docs and work like I have it above, but that’s where my search fails…

I really don’t know. :slight_smile: