Regular Expression Technique in ColdFusion
I'm new to Coldfusion and I've never really used regular expressions before. How would I write a ColdFusion function (or just a conditional statement) to check if a form variable is a match for an IP network (44.42.94.0/18)?
I'm just basically looking to see if the backslash "/" character is in the string.
There are actually plenty of well-developed regular expression strings available on the Internet, which you can simply "copy and use." You don't have to spend too much time figuring-out the correct pattern of chicken scratches.
It's not quite as convenient as saying "use Regexp::Common::URL;" but one cannot have everything in "less-enlightened" languages like CF...
You do need to understand them, however. When you look at the string given in a previous reply, you do need to understand the meaning of all those symbols, and you need to practice the art of being able to cook them up extemporaneously.
Similar Messages
-
Regular expression technique needed to eliminate " and replace with \"
I am trying to figure out the best way to fix data coming from a database table through the use of ColdFusion, in which there are some quotation marks that JavaScript Flash doesn't want in the array before adding the text content to a quiz.
At the moment, if there are any quotation marks in the elements of the array, even though each element is surrounded by quotation marks, I have to add a backslash to escape them.
I was wondering what would be the regular expression to use to do this, not for the quotation marks surrounding each element, but for those used inside of them.
For example,
["08 Working with Flash Forms_16",
"The syntax for the submit button was .",
"name="submit" type="submit"",
"name="submit"action="submit"",
"id="submit" type="submit"",
"id="submit"action="submit"",
"No, name="submit" type="submit" is correct.",
"true",
"false",
"false",
"false",
"897"] ,
is an example of an element created that has quotation marks inside of the quotation marks for each element.
I am debating about handling this either with XML by writing code to do that with ColdFusion instead of using the code I generated with ColdFusion to create this.
I am also debating about writing the regular expression in a way that I could use it from either ActionScript 2 or 3.0, going at it at the file level maybe.
At the moment I am opening the file and experimenting with writing a Find expression that uses regular expression to select what I want to change before changing it.Hi,
In excel menu Tools->macro
Enter the macro name say SAPBEXonRefresh
click 'create', will go to visual basic editor
To display '#' as '', paste the following code
Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
Dim c As Range
For Each c In resultArea.Cells
If c.Value = "#" Then c.Value = ""
Next c
End Sub
Close the editor and click on refresh again.
Thanks..
Shambhu -
This question was posted in response to the following article: http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a38 f-7fff.html
"ColdFusion supplies four functions that work with regular expressions" should be "ColdFusion supplies six functions that work with regular expressions,"
-
Regular Expression in CF ?
Hi
I have the following line from an rss feed
#weather_xml.rss.channel.item[x].description.xmlText#
At present it outputs as
Thursday: sunny, Max Temp: 8°C (46°F), Min Temp:
4°C (39°F)
Is it possible using regular expressions or another method,
that after each comma the script will insert a <br> tag so
all the data is not displayed on one line ?
Any ideas ?rambo wrote:
> But on the page it shows up as normal text i.e.
> REReplace(Max Temp: 8?C (46?F), Min Temp: 4?C (39?F),
Wind Direction: SSE,
> Wind Speed: 14mph, Visibility: moderate, Pressure:
1038mb, Humidity: 88%, UV
> risk: low, Sunrise: 08:12GMT, Sunset: 16:06GMT, ',', '
You do have to provide the basic CFML syntax of hash|pound|#
signs
around the function inside a
<cfoutput></cfoutput> block so that the
ColdFusion application server knows this is a statement to be
resolved,
not just text to display.
I.E.
<cfoutput>#replace(weather_xml.rss.channel.item[x].description.xmlText,
',', '<br>', 'ALL'>#</cfoutput> -
Hello All, Happy Holidays.
I'm creating a component in an application that is similar to
Facebook's "News Feed" feature. This feature lists rows from a
database which may contain some 'special text' that needs to be
converted to HTML. Note: I am storing the 'special text' in the
database instead of the actual html code to save space in the
database in case the name of the object is very long.
Here's what I'm trying to do:
In the database a record might look like this:
On 12/25/06 [user:253]John Smith[/a] Logged On.
When I display the table I want to convert it to the
following:
On 12/25/06 <a href="user_info.cfm?userId=253">John
Smith</a> Logged On.
I've been able to create the following regular expression
which does a good job converting the text to a link, but I am
unable to get the uniqueID (253) from the string. Note: Description
is the name of the column that is being processed.
<CFSET temp = ReReplace(Description,'\[User:.\]','<a
href="user_info.cfm?userID=253">','ALL')>
<CFSET temp =
ReReplace(temp,'\[/a\]','</a>','ALL')>
Is there a way I can convert the string in one regular
expression? Also, how can I get the number value after the colon
(:) and insert it into the replacement string?
Also, to complicate things, the string may have multiple
instances of 'special text'. For example:
On 12/25/06 [user:253]John Smith[/a] modified
[user:262]Captain Picard's[/a] account
Thanks for your help!If I read your requirement correctly, you should replace
this:
\[user:([^\]]*)](.*)?\[/a]
With this:
<a href="user_info.cfm?userId=\1">\2</a>
The bit you were missing from your regex was capturing the
subexpressions
for the ID and the name. Can I suggest you read this:
http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000990.htm,
and have
a bit of an experiment.
Also, Regex Coach is good for testing stuff:
http://weitz.de/regex-coach/
Adam -
Validate cfinput using regular expression
Hi,
can somebody help me valditing an cfinput field using regular expressions?
First digit must be a number or "R".
Digit 2-15 can be everything without special characters. Digit 2-15 can also be empty.
I try this, but it doesn't work (Sorry I'm a beginner using regex).
<cfinput type="text" name="field1" required="yes" validate="regular_expression" pattern="[0-9Rr][0-9a-zA-Z]*" maxlength="15">
Thank you in advice!
ClaudiaYou haven't told your regex to match the entire string, so it will "pass"
any string that has your match anywhere within it, so like as long as it's
got an R or a digit in it: it's OK.
To tell it to match the entire string, anchor it to the start and end of the
string with ^ and $ respectively.
Regular expression syntax: Using special characters
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a38f -7ffb.html#WSc3ff6d0ea77859461172e0811cbec0a38f-7fef
Adam -
String extract using regular expression
Hi
I have text like this "<a>45</a><ct>Hi</ct><R>45 85</R><H>Here</H>" .I want to extract using regular expression or any techniques the text between <R> and </R> also need to replace the space with pipe between 45 and 85 like "45|85"
Edited by: vishnu prakash on Mar 2, 2012 4:42 AMHi,
Here's one way:
REPLACE ( REGEXP_REPLACE ( txt
, '.*<R>(.*)</R>.*'
, '\1'
, '|'
)This assumes there is only one <R> tag in txt.
Always say which version of Oracle you're using. The expression above will work in Oralce 10 and up, but starting in Oracle 11 you can use REGEXP_SUBSTR rather than the less intuitive REGEXP_REPLACE.
Edited by: Frank Kulash on Mar 2, 2012 7:48 AM -
Search for a regular expression in TextEdit's Find panel?
Is it possible to search for a regular expression using TextEdit's Find panel? (This used to be possible in 'Step.)
Help yields nothing, but perhaps there's some hidden technique?
Thanks.What do you define as a "row"? Is each row a single array element? Since your array elements are strings, each array element itself could be a multiline|multirow string itself that might need to be analyzed one row at a time.
To look for patterns:
If you have LabVIEW 8.0 or higher, you can use "Match regular expression". Else you can use "Match Pattern". It really depends how specific you need to be. Are there lines that start with "Date:" but don't contain a formatted date afterwards?
To search for array elements starting with simple string "Date:", use "match first string".
LabVIEW Champion . Do more with less code and in less time . -
Getting the regular expression from the given text
Hi
I need to develope an application which can convert the given text into the regular expression. I need that when i enter any text in textarea that should be translated into regular expression in another panel. but i could not find the method or technique which can do so. plz help me to resolve this issue.
Thanks Imran khan.well, there are an infinite number of regular expressions for an arbitrary piece of text, so you will have to qualify in your mind what the purpose of the regular expression is.
For instance, it is trivial to create a regex for a string just by copying the input text, and inserting \ before any special characters. But this pattern would probably be quite silly. -
Regular expression and output format
hi all,
i have following scenario-
regular expression: [0-9]{3}-[0-9]{3}-[0-9]{4}
generated value by the above regular expression: 123-234-6789
output format to display the generated above value: xxx-xxx-$1
now i need to display the generated value (123-234-6789) in the specified output format (xxx-xxx-$1) and the final output will be xxx-xxx-6789
how is it possible?
Note: here regular expression and output format can vary
br,
basharHi, Bashar
You can solve this problem by using the Data Masking Technique.
Masking data means replacing certain fields with a Mask character (such as an X). This effectively disguises the data content while preserving the same formatting on front end screens and reports. For example, a column of credit card numbers might look like:
4346 6454 0020 5379
4493 9238 7315 5787
4297 8296 7496 8724
and after the masking operation the information would appear as:
4346 XXXX XXXX 5379
4493 XXXX XXXX 5787
4297 XXXX XXXX 8724
The masking characters effectively remove much of the sensitive content from the record while still preserving the look and feel. Take care to ensure that enough of the data is masked to preserve security.
It would not be hard to regenerate the original credit card number from a masking operation such as: 4297 8296 7496 87XX since the numbers are generated with a specific and well known checksum algorithm.
Best Regards,
Mahfuz Khan -
Handling Regular expression ambiguitie s
Hi All,
I am attemting to make my own regular expression class. (Just for fun) :)
I have successfully converted the regular expression into a DFA ( deterministic finite automaton ). However, as i have noticed, there is still ambiguity in transition when it comes to certain classes of regular expressions such as a+[^0-9]+w. this means one or more a's followed by one or more symbols that are NOT numbers, followed by a w. Now if we have a string "aaaw", the first a is matched quite nicely, but should the second 'a' be treated as an a that is to be matched with "a+" or "[^0-9]" ??
Is there any algorithm that resloves such an ambiguity?
Any help would be much appreciated. I am stuck with this issue and don't seem to have any leads at all :)Hi All,
My problem is now solved. I have refined the suggestions to come up with the following algorithm ( excuse the errors, and ineffeciencies, if any )
push all DFA states into a queue
while !(dfaStateQueue.empty())
currentDFAState = dfaStateQueue.pop()
push all transitions of currentDFAState to transitionQueue.
store all transitions into transitionArray.
while ( !transitionQueue.empty() )
compareWithTransition = transitionQueue.pop();
for(i = 1 to length(transitionArray) )
compareWithTransition = transitionArray;
Set intersec = set_intersection(compareWithTransition.getChars, compareToTransition.getChars);
if( !intersect.empty() )
//characters in compareWith but not in compareTo
Set minus1 = set_difference(compareWithTransition, compareToTransition)
//characters in compareTo but not in compareWith.
Set minus2 = set_difference(compareToTransition, compareWithTransition)
//compareWithTransition is subset of compareToTransition
if(minus1.empty())
replace characters of compareTo with characters in set minus2
replace characters of a closure transition of compareTo
with characters in set minus2
compareWithTransition.nextDfa.addAllTransitions
(compareToTransition.nextDfa.getTransitions())
continue
//compareToTransition is subset of compareWithTransition
else if(minus2.empty())
replace characters of compareWithTransition with characters in set minus1
replace characters of a closure transition of compareWithTransition
with characters in set minus2
compareToTransition.nextDfa.addAllTransitions
(compareWithTransition.nextDfa.getTransitions())
continue;
end if
create new DFA state D;
currentDFAState.addTransition(intersect, D);
push D onto queue.
D.addAllTransitions(compareWithTransition.nextDfa.getTransitions());
D.addAllTransitions(compareToTransition.nextDfa.getTransitions());
replace characters of compareWithTransition with characters in set minus1
replace characters of compareToTransition with characters in set minus2
end if
end for
end while
end while
I hope this helps everyone at large. Now there is no need for backtracking at all and DFAs are now truly "DFAs" :)
I dont know if other tools employ this technique or not. Please ignore the glaring ineffeciencies. I have give the algorithm the way i coded it ( Never considered myself as effecient programmer in the first place) HAHAHA
Chears,
AUTOMATON -
Logical AND in Java Regular Expressions
I'm trying to implement logical AND using Java Regular Expressions.
I couldn't figure out how to do it after reading Java docs and textbooks. I can do something like "abc.*def", which means that I'm looking for strings which have "abc", then anything, then "def", but it is not "pure" logical AND - I will not find "def.*abc" this way.
Any ideas, how to do it ?
BakenFirst off, looks like you're really talking about an "OR", not an "AND" - you want it to match abc.*def OR def.*abc right? If you tried to match abc.*def AND def.*abc nothing would ever match that, as no string can begin with both "abc" and "def", just like no numeric value can be both 2 and 5.
Anyway, maybe regex isn't the right tool for this job. Can you not simply programmatically match it yourself using String methods? You want it to match if the string "starts with" abc and "ends with" def, or vice-versa. Just write some simple code. -
Hello..
I wanted to write a regular expression to match the foll string..
<!--endclickprintexclude--><!--startclickprintexclude--> <!--endclickprintexclude-->
<p> <b>NEW ORLEANS, Louisiana (CNN) </b>
-- Two years after Hurricane Katrina devastated coastal areas of Louisiana and Mississippi, residents say much of America has forgotten their plight.
</p> <!--startclickprintexclude-->
I tried doing..
Matcher matcher= Pattern.compile("<!--endclickprintexclude--> <p><b>([^<^>]+?)</p><!--startclickprintexclude-->", Pattern.CASE_INSENSITIVE).matcher(story);
Its not working...
is there any other soln?Theres probably a better way to do this but here's a way that works.
import java.util.regex.*;
public class RegexTester{
public static void main(String[] args){
String text =
"<!--endclickprintexclude--><!--startclickprintexclude--> <!--endclickprintexclude-->" +
"<p> <b>NEW ORLEANS, Louisiana (CNN) </b>" +
"-- Two years after Hurricane Katrina devastated coastal areas of Louisiana and Mississippi," +
"residents say much of America has forgotten their plight." +
"</p> <!--startclickprintexclude-->";
String regex = ">((?:\\s*[\\S&&[^<>]]+\\s*)*?)<";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(text);
while(m.find()){
System.out.println("Match: '" + m.group(1) + "'");
} -
Help in regular expression matching
I have three expressions like
1) [(y2009)(y2011)]
2) [(y2008M5)(y2011M3)] or [(y2009M5)(y2010M12)]
3) [(y2009M1d20)(y2011M12d31)]
i want regular expression pattern for the above three expressions
I am using :
REGEXP_LIKE(timedomainexpression, '???[:digit:]{4}*[:digit:]{1,2}???[:digit:]{4}*[:digit:]{1,2}??', 'i');
but its giving results for all above expressions while i want different expression for each.
i hav used * after [:digit:]{4}, when i am using ? or . then its giving no results. Please help in this situation ASAP.
ThanksI dont get your question Can you post your desired output? and also give some sample data.
Please consider the following when you post a question.
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude. -
Hi
I want to retrieve the data if the data contains a character or a space or '-' thru select query .
Please help me in writing the combination of 3 with regular expression.
Thanks!!VT wrote:
Hi,
Try this
SELECT *
FROM <TABLE> WHERE REGEXP_LIKE(<COLUMN>, '[a-z -][A-Z -]');cheers
VTThat won't work as it's expecting at least two characters with the first having to be a-z (lower case) or space or "-" followed by A-Z (upper case) or space or "-".
The correct way is either:
[a-zA-Z -]or
[[:alpha:] -]using the alpha set is often preferable as it can work differently with different character sets/languages rather than restricting to just the a-zA-Z ranges.
Generating a reference for your own database characterset/language can be useful...
SQL> select level-1 as asc_code, decode(chr(level-1), regexp_substr(chr(level-1), '[[:print:]]'), CHR(level-1)) as chr,
2 decode(chr(level-1), regexp_substr(chr(level-1), '[[:graph:]]'), 1) is_graph,
3 decode(chr(level-1), regexp_substr(chr(level-1), '[[:blank:]]'), 1) is_blank,
4 decode(chr(level-1), regexp_substr(chr(level-1), '[[:alnum:]]'), 1) is_alnum,
5 decode(chr(level-1), regexp_substr(chr(level-1), '[[:alpha:]]'), 1) is_alpha,
6 decode(chr(level-1), regexp_substr(chr(level-1), '[[:digit:]]'), 1) is_digit,
7 decode(chr(level-1), regexp_substr(chr(level-1), '[[:cntrl:]]'), 1) is_cntrl,
8 decode(chr(level-1), regexp_substr(chr(level-1), '[[:lower:]]'), 1) is_lower,
9 decode(chr(level-1), regexp_substr(chr(level-1), '[[:upper:]]'), 1) is_upper,
10 decode(chr(level-1), regexp_substr(chr(level-1), '[[:print:]]'), 1) is_print,
11 decode(chr(level-1), regexp_substr(chr(level-1), '[[:punct:]]'), 1) is_punct,
12 decode(chr(level-1), regexp_substr(chr(level-1), '[[:space:]]'), 1) is_space,
13 decode(chr(level-1), regexp_substr(chr(level-1), '[[:xdigit:]]'), 1) is_xdigit
14 from dual
15 connect by level <= 256
16 /
ASC_CODE C IS_GRAPH IS_BLANK IS_ALNUM IS_ALPHA IS_DIGIT IS_CNTRL IS_LOWER IS_UPPER IS_PRINT IS_PUNCT IS_SPACE IS_XDIGIT
0 1
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1 1
10 1 1
11 1 1
12 1 1
13 1 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 1 1 1
33 ! 1 1 1
34 " 1 1 1
35 # 1 1 1
36 $ 1 1 1
37 % 1 1 1
38 & 1 1 1
39 ' 1 1 1
40 ( 1 1 1
41 ) 1 1 1
42 * 1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1 1 1 1 1
119 w 1 1 1 1 1
120 x 1 1 1 1 1
121 y 1 1 1 1 1
122 z 1 1 1 1 1
123 { 1 1 1
124 | 1 1 1
125 } 1 1 1
126 ~ 1 1 1
127 1
128 Ç 1 1 1
etc.
{code}
Maybe you are looking for
-
Can't connect MacBook Pro to Clear 4G router
I have a mid 2010 MBP running 10.6.8 & recently purchased Clear 4G as my ISP. I bought the Express Hub which works great and connects with every device I have; PlayStation 3, iPhone, iPad, Apple TV, and both a Win7 & Linux netbooks. Only my MBP won't
-
Windows update 8.1 in my netbook
Good morning. When I bought my Satellite C50-B a week ago I turned off Windows Update. Actually my notebook is working great, but I want to know if you think it´s necessary to run WU manually some times for updating all or if I can stay Ok with the
-
Where the process start in implementin APO - DP project?
Hi Experts, Can anyone explain me in detail how and where the project start? According to my knowledge, Decisions will be as follows: 1. Forecast model i.e., whether causal or univariate. 2. Life Cycle Planning (Phase In/Out) 3. Promotion Planning 4.
-
Tlftextfiled in textarea as3 component problem?
i customize as3 textarea component (in source : fl.control.TextArea) i chnage textField in source to tlfTextFiled and i cand see RTL text in textArea component, but i have a problem , and i can not see affect my change in Direction please help me to
-
How can I flush/repair installed programs in the Application Manager / Creative Cloud?
Hi. I had installed a few of the Adobe programs through the Application Manager/Creative Cloud service on a Windows 7 system. The system crashed, forcing me to recover from a prior time backup, which was from before I installed the programs. Now, the