Jump to content

And yet another StringRegExp question...


Recommended Posts

I don't know that because i'm not perfectly fluent in English or not, but StringRegExp still seems very complicated to me.

I have a PHP file with this type of content:

$PUBLISHED_FOLDERS = array(
"1" => array("name" => "Client1", "path" => "/BEA/clientlogin1"),
"2" => array("name" => "Client2", "path" => "/CENTROOESTE/clientlogin2"),
"3" => array("name" => "Client3", "path" => "/COMEC"),
);

So, i do a FileRead and a StringRegExp to extract the contents BEA, CENTROOESTE and COMEC like this:

$sFile = FileRead("configuration.php")
$aFilter = StringRegExp($sFile, '(?U)"path" => "/(.*)\W', 3)

And it works like a charm, but today i needed to add a value with a symbol (no '/' ofcourse) or a space and in the results nor the symbols nor the spaces appear.

For example, if i have a value 'CENTRO OESTE' instead of 'CENTROOESTE', only the first word appears. And if i have a value 'B&A' instead of 'BEA', only 'B' appears in the result.

Can i add the ability to not ignore symbols or spaces in the StringRegExp above? Ofcourse the '/' couldn't be ignored, as i only need the first value after the first '/'.

I hope you guys can help me with this, and i hope i'm not being to complicated in the explanation. :huh2:

Link to comment
Share on other sites

Im sure a cool kid will do it one regular expression, i need one and a replace :huh2:

#include <array.au3>

$sFile = FileRead("configuration.php")

$aFilter = StringRegExp($sFile, '(?U)"path" => "/(.*?)"', 3)

for $i = 0 to ubound($aFilter) - 1
    $aFilter[$i] = stringregexpreplace ($aFilter[$i] , "/(.*)" , "")
Next

_ArrayDisplay($aFilter)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

And it works like a charm, but today i needed to add a value with a symbol (no '/' ofcourse) or a space and in the results nor the symbols nor the spaces appear.

For example, if i have a value 'CENTRO OESTE' instead of 'CENTROOESTE', only the first word appears. And if i have a value 'B&A' instead of 'BEA', only 'B' appears in the result.

Can i add the ability to not ignore symbols or spaces in the StringRegExp above? Ofcourse the '/' couldn't be ignored, as i only need the first value after the first '/'.

Till something better.. try this:

$aFilter = StringRegExp($sFile, '"path" => "/(.+?)["|/]', 3)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...