It is currently March 29th, 2024, 1:43 pm

Help with RegExp Expression

Get help with creating, editing & fixing problems with skins
mcpaton
Posts: 27
Joined: March 17th, 2016, 2:18 am

Help with RegExp Expression

Post by mcpaton »

Hi Guys

I've got an expression that doesn't always return the same value. Most times, it returns result number 1 inside " " marks. However if there's no result, it returns the word null but with no " " marks around it. As I don't want to display the " " marks, my expression parses them out. However if the result is null, it breaks the whole expression...

My Expression:

Code: Select all

(?siU)Title":"(.*)".*Image":{"Url":"(.*)".*
Result when null

Code: Select all

{"Title":null,"Image":{"Url":"http://image.jpg"}
Result when working:

Code: Select all

{"Title":"The Title","Image":{"Url":"http://image.jpg"}
Any tips on how to deal with this would be appreciated

Thanks
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Help with RegExp Expression

Post by FreeRaider »

Instead of only capturing the number, you can capture it including the quotes, and then use a substitute option.

For capture the number including the quotes:

Code: Select all

.*Title":(.*)$
If you want more help, please you post the entire skin (including images, scripts, and everything else).
mcpaton
Posts: 27
Joined: March 17th, 2016, 2:18 am

Re: Help with RegExp Expression

Post by mcpaton »

Thanks. I ended up grabbing the whole field (either null or "title") and then substituting the word null, or the " character to remove them. Worked nicely in the end.

Cheers
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Help with RegExp Expression

Post by FreeRaider »

Well done!