Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When using text comparison it would be nice to be able to use some of the flags (global, ignoreCase, etc). Would this/is this possible?
Best, tim
Comment | File | Size | Author |
---|---|---|---|
#19 | Fixed coding standards-1627708.patch | 3.22 KB | zvonimirr |
#15 | Support flags via custom regex-1627708.patch | 3 KB | zvonimirr |
|
Comments
Comment #1
timodwhit CreditAttribution: timodwhit commentedLooking into it further, it looks like the reason the flags aren't allowed in the comparison is because
instead of
It make sense why this is the case. But is there a way to have the code look like:
Where $text3 is the select list of flags?
Comment #2
timodwhit CreditAttribution: timodwhit commentedComment #3
mitchell CreditAttribution: mitchell commentedFlag support for regex?? Huh?..
http://livedocs.adobe.com/flex/3/html/12_Using_Regular_Expressions_10.html
http://gskinner.com/RegExr/ : UI also has this with some nice help text.
Everything is possible! ..but what an unfortunate terminology.
I guess these could be checkbox options, similar to RegExr.
Follow-up once we add this here: #1658092: Action: Regular Expression
Comment #4
Bobcrum CreditAttribution: Bobcrum commentedThis would be immensely helpful for states like California, whose tax codes are insane... I would use it for ignoring the case on City names that are used to calculate taxes. As it stands now, I need to write separate rules for EVERY case permutation on 24 counties.
Comment #5
zonesny CreditAttribution: zonesny commentedHi. Is there any movement on this feature request (i.e. implementing regex flags)? The original post was made in June 2012, and this is a much needed enhancement.
The following issue posts are all related to the need for this feature (and this is only a sample):
Comment #6
zonesny CreditAttribution: zonesny commentedWhile this feature should be properly implemented via the plugin (and checkboxes as the original poster suggested), if you desperately need the flags, and don't mind having them applied to all of your Rules regex, you could use the following hack in rules/modules/data.eval.inc:
NOTE: the global (g) modifier does not exist, instead preg_match_all must be used, and a third parameter array must be passed.
Comment #7
TR CreditAttribution: TR commentedStill in need of a patch here ...
Also need a test case.
Comment #8
TR CreditAttribution: TR commentedWe're not really adding new features this late in the D7 development cycle. Because there has been no community contribution for this feature in the form of a patch and/or test I'm moving this to D8 for consideration.
If you're interested in seeing this feature in Rules, please contribute a patch so we can review and discuss it.
Comment #9
zvonimirrHere is a quick patch that allows you to write regex the old way or the new (custom) way which includes flags.
Comment #10
zvonimirrComment #11
zvonimirrComment #12
TR CreditAttribution: TR commentedis_countable() is only available for PHP 7.3.0+, but Drupal 8 is still supposed to run with PHP 7.0, and even PHP 5.5 for some currently-supported versions of core.
There also needs to be new tests with this patch to test that flags work. Testing just one flag would be sufficient.
Comment #13
zvonimirrAh yes, I've added a test for the case-insensitive flag.
Comment #14
zvonimirrComment #15
zvonimirrComment #16
zvonimirr@TR, #14 and #15 share the same name, but I accidentally uploaded the wrong version on #14. That's why it isn't tested.
Comment #17
zvonimirrComment #18
TR CreditAttribution: TR commentedI don't like the use of
function_exists('is_countable')
- that should be used only if there is absolutely no other way possible.Note there are also a few easy-to-fix coding standards issues in the patch. See the test results for details.
Comment #19
zvonimirrComment #20
zvonimirrComment #21
zvonimirr@TR do you think that the latest patch is good?