Welcome, Guest
Username: Password: Remember me

TOPIC: Reverse Regular Expression

Reverse Regular Expression 3 years 4 months ago #58630

  • scalprum
  • scalprum's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
I would like to use the reverse regular expression of the following line:

^104[6-8]\s?[a-zA-Z]{2}$

Could someone help me?
The administrator has disabled public write access.

Re: Reverse Regular Expression 3 years 4 months ago #58643

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
What do you mean by "reverse".

A far as I can tell, that regex will search for a string like "1046ab" or "1046 AB". Can you tell us what you would like to search for?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 4 months ago by tpartner.
The administrator has disabled public write access.

Re: Reverse Regular Expression 3 years 4 months ago #58646

  • scalprum
  • scalprum's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
I like to search for everything but the string like "1046ab" or "1046 AB".

So the opposite of the regular exprssion: ^104[6-8]\s?[a-zA-Z]{2}$

Thanks!
The administrator has disabled public write access.

Re: Reverse Regular Expression 3 years 4 months ago #58647

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
As far as I know, there is no "opposite" for regexes.

You will need to use a script like the following to validate against the regex. (replace"QQ" with a text question ID)
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
		var patternMatch = /^104[6-8]\s?[a-zA-Z]{2}$/;
 
		// A listener on the input to validate against the regex
		$('#question'+qID+' input.text').change(function() {
 
			if (patternMatch.test($(this).val()) != true) {
				alert ('Wrong!');
			}
			else {
				alert ('Right!');
			}
		});
 
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.110 seconds
Donation Image