@@ -271,6 +271,9 @@ class RegExpTerm extends RegExpParent {
271
271
272
272
/** Holds if this regular expression term can match the empty string. */
273
273
predicate matchesEmptyString ( ) { none ( ) }
274
+
275
+ /** Gets a string matched by this regular expression. */
276
+ string getAMatch ( ) { none ( ) }
274
277
}
275
278
276
279
/**
@@ -457,6 +460,20 @@ class RegExpSequence extends RegExpTerm, TRegExpSequence {
457
460
override predicate matchesEmptyString ( ) {
458
461
forall ( RegExpTerm child | child = this .getAChild ( ) | child .matchesEmptyString ( ) )
459
462
}
463
+
464
+ // Why can't we use concat(...) with language[monotonicAggregates] here instead?
465
+ override string getAMatch ( ) { result = this .getAMatchFromChildAtIndex ( 0 ) }
466
+
467
+ private string getAMatchFromChildAtIndex ( int i ) {
468
+ i = this .getNumChild ( ) and result = ""
469
+ or
470
+ exists ( string substring , string rest |
471
+ substring = this .getChild ( i ) .getAMatch ( ) and
472
+ rest = this .getAMatchFromChildAtIndex ( i + 1 )
473
+ |
474
+ result = substring + rest
475
+ )
476
+ }
460
477
}
461
478
462
479
pragma [ nomagic]
@@ -688,6 +705,8 @@ class RegExpCharacterClass extends RegExpTerm, TRegExpCharacterClass {
688
705
override string getAPrimaryQlClass ( ) { result = "RegExpCharacterClass" }
689
706
690
707
override predicate matchesEmptyString ( ) { none ( ) }
708
+
709
+ override string getAMatch ( ) { not this .isInverted ( ) and result = this .getAChild ( ) .getAMatch ( ) }
691
710
}
692
711
693
712
/**
@@ -802,6 +821,8 @@ class RegExpConstant extends RegExpTerm {
802
821
override string getAPrimaryQlClass ( ) { result = "RegExpConstant" }
803
822
804
823
override predicate matchesEmptyString ( ) { none ( ) }
824
+
825
+ override string getAMatch ( ) { result = this .getValue ( ) }
805
826
}
806
827
807
828
/**
@@ -851,6 +872,8 @@ class RegExpGroup extends RegExpTerm, TRegExpGroup {
851
872
override string getAPrimaryQlClass ( ) { result = "RegExpGroup" }
852
873
853
874
override predicate matchesEmptyString ( ) { this .getAChild ( ) .matchesEmptyString ( ) }
875
+
876
+ override string getAMatch ( ) { result = this .getAChild ( ) .getAMatch ( ) }
854
877
}
855
878
856
879
/**
0 commit comments