Using Boundaries
Regex : cat
he cat scattered his food all over the room.
Sử dụng biên với \b
Regex : \bcat\b --> từ cat
The cat scattered his food all over the room.
Làm thế nào để định nghĩa giới hạn của 1 xâu bất kì ?
Vd : muốn lấy <xml version="1.0" ?>
trong :
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://tips.cf"
xmlns:impl="http://tips.cf" xmlns:intf="http://tips.cf"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
Regex : <\?xml.*\?> --> hay hơn có thể dùng ^\s*<\?xml.*\?>
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://tips.cf"
xmlns:impl="http://tips.cf" xmlns:intf="http://tips.cf"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
Using Multiline Mode
Regex : (?m)^\s*//.*$
<SCRIPT>
function doSpellCheck(form, field) {
// Make sure not empty
if (field.value == '') {
return false;
}
// Init
var windowName='spellWindow';
var spellCheckURL='spell.cfm?formname=comment&fieldname='+field. name;
// Done
return false;
}
</SCRIPT>
(?m) :