To the point: what I am looking for is a relatively clean way to say "any front anchored substring of $word" in regex.
If $word='ello', then
should match 'h','he','hel', etc.my $magicRegex = munge($word); if (/^h$magicRegex$/) {...}
Background: (aka, XY-problem repellent)
I have a text-based combat game I'm working on, which involves the player sending commands such as
The backend physics code works fine, but the english parsing is not as flexible as it could be.
I've come up with a decent way to allow the parameters to be listed in any order, provided that the tags "dispersion" and "offset" are present to identify which number is which:
my $number = qr#(-?\d+\.?\d*)#; my $mixNmatch = qr#(?:(?:\s+[d][a-z]*\s+$number)|(?:\s+[oa][a-z]*\s+$n +umber))*#; while ($_ = <>) { no warnings; # dealing with undefs is clutter for this example print /^lock$mixNmatch\s*$/i ? "Yes: disp=$1, offset=$2\n" : "nope\n +"; }
The idea being that "d", "disp" and "dispersion" are all acceptable to mark a dispersion, while "offset", "angle", "ang", etc are all acceptable to mark an offset/angle. The ugly part is that "awoogha" also counts as marking an angle simply because it starts with an 'a'.
And thus I ask, is there a better way, or is this good enough?
In reply to Regex - Matching prefixes of a word by SuicideJunkie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |