preg_match / preg_replace == NULL

G

GCOINC

Guest
Where is this functionality in this language.

Example:
B4X:
$str = "{abc|123|zzz} in some {place|house}"
preg_match("/{[^{}]+?}/", $str, $match)

$attack = explode("|", $match[0]);

$new_str = preg_replace("/[{}]/", "", $attack[rand(0,(count($attack)-1))]);

$str = str_replace($match[0], $new_str, $str);

var_dump($str);

Sooooo...... :sign0163:
 
G

GCOINC

Guest
:signOops:
That thread is useful for simple regex, however, if you look at the above,

I am looking for equivalent commands that pass back and operate the same fashion as PHP. Perhaps someone could write a native class with the same functions and global return.

Note: $matches ... is a variable that is filled with multiple multi-dimensional arrays containing the data for results in various formats and the overall command returns nothing, or boolean depending on if the set was filled.

In the current context, this set of commands would be contained within a loop until no matches are found, and preg_replace can use the subset of results to return a single random result for each of the inner blocks it is parsing for.

Currently, the way to do this with the very limited and basic command set (more limited than basic itself), do not appear to permit this, so I am asking, which commands are available to do this in like fashion -- and if there is none that match, can you please integrate these two commands in full functionality in your core application.

I could find no examples on how this was done in Java, however if you look for Spintax parser in java, and find one that works, I am sure you could port.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why aren't you using the spintax code that I wrote??

Currently, the way to do this with the very limited and basic command set (more limited than basic itself)
Basic4android Regex object support the same regular expression methods that Java support. I found these methods to be very powerful. You should properly understand how to work with Matcher.
 
Upvote 0
Top