String GSTINFORMAT_REGEX = "[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}";
I want to create this expression in xbase++. Please tell me how to create this kind of expression.
Thanks in advance.
Try this:
GSTINFORMAT_REGEX = "[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}";
oRegExp = CreateObject("VBScript.RegExp")
oRegExp.Pattern = GSTINFORMAT_REGEX
result = oRegExp.test(testphrase)
Related
Please, take a look at following code:
var platNom = "apero"; // I set the value of my attribute in one variable
var monAttribut = ds.Convives.attributes[platNom]; //this works
var invitants = ds.Convives.query("$(this[platNom] == 'oui') ", {allowJavascript: true});// This does not work
Is there a problem in my syntax?
If I understand correctly you would like to use attribute variable to construct the query string. Then you can do this by simply reference platNom directly.
The correct syntax should be:
var invitants = ds.Convives.query(platNom + " == 'oui'")
I have a string like this:
let str = "<mylabel>Here is a label</mylabel>"
How can I get a substring with the text "Here is a label" ? Is there any fancy way to do this or do I have to use componentsSeparatedByString?
Many thanks
You can use NSAttributedString(HTML:, documentAttributes:) to extract simple HTML entities:
let str = "<mylabel>Here is a label</mylabel>"
if let html = str.dataUsingEncoding(NSUTF8StringEncoding), let result = NSAttributedString(HTML: html, documentAttributes: nil) {
print(result.string) // "Here is a label"
}
For more complex work, it would be better to use NSXMLParser or a third-party library.
This sorted the issue:
let str = "<mylabel>Here is a label</mylabel>"
let startIndex = str.rangeOfString("<mylabel>")!.last!
let endIndex = str.rangeOfString("</mylabel>")!.first!
print(str.substringWithRange(Range<String.Index>(start: startIndex.advancedBy(1), end: endIndex)))
While you generally would not want to use regular expressions to parse XML/HTML, if you know it will have <mylabel> and </mylabel> you can do something like:
let result = str.stringByReplacingOccurrencesOfString("<mylabel>(.*)</mylabel>", withString: "$1", options: .RegularExpressionSearch, range: nil)
Currently I have something like this
$route['ourworks/client'] = "ourworks/ourwork_item/client";
$route['ourworks/portfolio'] = "ourworks/ourwork_item/portfolio";
$route['ourworks/casestudy'] = "ourworks/ourwork_item/casestudy";
Is there anyway that I could make these 3 lines a a dynamic line?
Thank you
Should work:
$route['ourworks/([a-z]+)'] = "ourworks/ourwork_item/$1";
To allow the other permitted chars use this:
$route['ourworks/(:any)'] = "ourworks/ourwork_item/$1";
I have a string containing a path:
/var/www/project/data/path/to/file.mp3
I need to get the substring starting with '/data' and delete all before it. So, I need to get only /data/path/to/file.mp3.
What would be the fastest solution?
'/var/www/project/data/path/to/file.mp3'.match(/\/data.*/)[0]
=> "/data/path/to/file.mp3"
could be as easy as:
string = '/var/www/project/data/path/to/file.mp3'
path = string[/\/data.*/]
puts path
=> /data/path/to/file.mp3
Using regular expression is a good way. Though I am not familiar with ruby, I think ruby should have some function like "substring()"(maybe another name in ruby).
Here is a demo by using javascript:
var str = "/var/www/project/data/path/to/file.mp3";
var startIndex = str.indexOf("/data");
var result = str.substring(startIndex );
And the link on jsfiddle demo
I think the code in ruby is similar, you can check the documentation. Hope it's helpful.
Please try this:
"/var/www/project/data/path/to/file.mp3".scan(/\/var\/www(\/.+)*/)
It should return you all occurrences.
How can you check if a string is a valid GUID in vbscript? Has anyone written an IsGuid method?
This function is working in classic ASP:
Function isGUID(byval strGUID)
if isnull(strGUID) then
isGUID = false
exit function
end if
dim regEx
set regEx = New RegExp
regEx.Pattern = "^({|\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\))?$"
isGUID = regEx.Test(strGUID)
set RegEx = nothing
End Function
This is similar to the same question in c#. Here is the regex you will need...
^[A-Fa-f0-9]{32}$|^({|()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|))?$|^({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2}, {0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})$
But that is just for starters. You will also have to verify that the various parts such as the date/time are within acceptable ranges. To get an idea of just how complex it is to test for a valid GUID, look at the source code for one of the Guid constructors.
In VBScript you can use the RegExp object to match the string using regular expressions.
Techek's function did not work for me in classic ASP (vbScript). It always returned True for some odd reason. With a few minor changes it did work. See below
Function isGUID(byval strGUID)
if isnull(strGUID) then
isGUID = false
exit function
end if
dim regEx
set regEx = New RegExp
regEx.Pattern = "{[0-9A-Fa-f-]+}"
isGUID = regEx.Test(strGUID)
set RegEx = nothing
End Function
there is another solution:
try
{
Guid g = new Guid(stringGuid);
safeUseGuid(stringGuid); //this statement will execute only if guid is correct
}catch(Exception){}