Reg exp in form
Hello,
I need some help on reg expressions.
I want to allow users to type a url on my html page. The way I currently handle this situations is this:
myString = myString.replaceAll("(?:https?|ftp)://\\S+(?<![,.?!)])", "<a href=\"$0\">$0</a>");
so when the user types in a url such as http://www.java.sun it would display it back as a url that he/she can click on. This part works fine
However, if the user types in something like this:
<img src="http://www.someUrl.com/img.gif"/> it fails. In this case the user should see the image but he/she does not.
How can I make sure that only those instances get replaced where only URL is typed which is not part of other html. Should I add blank spaces before and after the url?
Thank you.
Will there be any links in the source document that are already in the processed format? That is, http://www.somewhere.org/If so, you'll need to match the whole element so don't accidentally match a URL within it. Then you can deal with the situation you brought up, where a start tag has a URL attribute. For that, just match any complete start tag and plug it back in. That should take care of any URL's that are contained within larger structures, leaving only "naked" URL's that need to be processed.
A simple replaceAll() won't work here, because you're doing different things with the text depending on what was matched. The Matcher class provides lower-level operations that let you do that kind of thing, but Elliott Hughes has written a nice little utility called Rewriter that does most of the work for you. Here's how you might use it: String regex = "(?is)" // CASE-INSENSITIVE and DOTALL modes
+ "<a\\s[^>]++>.*?</a>" // a complete A element
+ "|" // or
+ "<[a-z]+\\s[^>]++>" // a start tag with attributes
+ "|" // or
+ "(?:https?|ftp)://\\S+(?<![,.?!)])"; // a URL
Rewriter rewriter = new Rewriter(regex)
public String replacement()
String found = group(0);
return found.startsWith("<") ? found :
"<a href=\"" + found + "\">" + found + "</a>";
String resultStr = rewriter.rewrite(args[0]);
Similar Messages
-
Hi friends,
Please clarify the following doubt in Reg Exp.
Table EMP has following EMP_NAMEs:
============
Anand
Bala_G
Chitra
David_C
Elango
Fathima
============
We have a set of characters as "abcdefghijklmnopqrstuvwxyz0123456789".
Now we need to find the count of EMP_NAMES whose characters (any) are not in the list of characters in the above list. In this example, the result should be 2. i.e., 'Bala_D' and 'David_C'. The query should be like:
Declare
v_string varchar2(50) := 'abcdefghijklmnopqrstuvwxyz0123456789';
v_count number(6);
Begin
select count(*)
into v_count
from emp
where regexp_like(emp_name, v_string);
dbms_output.put_line(v_count);
end;
========================
Thanks in advance!Hi,
Welcome to the forum!
To use REGEXP_LIKE, you could say:
WHERE REGEXP_LIKE ( emp_name
, '[^abcdefghijklmnopqrstuvwxyz0123456789]'
)However, it will be faster not to use regular expressions:
WHERE LTRIM ( emp_name
, 'abcdefghijklmnopqrstuvwxyz0123456789'
) IS NOT NULLEdited by: Frank Kulash on Oct 10, 2012 4:18 PM
Removed extra single-quote, after DAMorgan, below. -
How to make Matcher stop once a reg exp match is found
Is there a way to make the regular expression Matcher stop reading from the underlying CharSequence once it finds a match? For example, if I have a very long String and a match for some regular expression is at the beginning of the String, can I make the Matcher object stop examining the String once it finds the match? The Matcher object seems to always examine the entire CharSequence, even if a match is very near the beginning.
Thanks,
Zach Cox
[email protected]Nope, {1}+ doesn't work either. I know it's
continuing because I created my own CharSequence
implementation that just wraps a String orwhatever,
and I print to System.out whenever Matcher callsthe
charAt method.What about the lookingAt() method?I think lookingAt is like matches, except just the beginning of the CharSequence has to match (i.e. starting at index 0), not the entire thing. I tried it and it doesn't even find the reg exp. The find method at least finds the reg exp, it just reads too far. -
Not often I ask questions myself, and perhaps my mind's just gone fuzzy this morning, but I'm having trouble doing a simple replace with regular expressions...
In the below example I just want to replace all occurences of "fred" with "freddies"...
SQL> ed
Wrote file afiedt.buf
1* select regexp_replace('this freddies is fred fred record', 'fred', 'freddies') from dual
SQL> /
REGEXP_REPLACE('THISFREDDIESISFREDFREDRECORD'
this freddiesdies is freddies freddies recordbut, obviously, I don't want the existing "freddies" to become "freddiesdies", it should stay as it is. So if I check for spaces either side of the search string (and take account of it maybe being at the start/end of the string...
SQL> ed
Wrote file afiedt.buf
1* select regexp_replace('this freddies is fred fred record', '(^| )fred( |$)', '\1freddies\2') from dual
SQL> /
REGEXP_REPLACE('THISFREDDIESISFREDFRE
this freddies is freddies fred record
SQL>It no longer replaces the "freddies" incorrectly, BUT it only replaces the first occurence of "fred" with "freddies" and not the latter one. ?!?!?!
If I put an extra space inbetween the two "fred"s then it works:
SQL> ed
Wrote file afiedt.buf
1* select regexp_replace('this freddies is fred fred record', '(^| )fred( |$)', '\1freddies\2',2) from dual
SQL> /
REGEXP_REPLACE('THISFREDDIESISFREDFREDRECO
this freddies is freddies freddies record
SQL>But I'm not going to have double spaces between the words and I can't determine where to insert them to make it work like this so it's not a feasible solution, although it does seem to highlight that the regular expression parser is not taking the space after the first match in the context of being the space before the second match.
Is that a bug in the regular expression parser, a feature of the way regular expressions work (i.e. expected) or am I doing something wrong with my search and replace reg.exp. strings?
CheersI think this will explain ..
SQL> select regexp_replace
2 ('this freddies is fred fred fred record',
3 '(^| )(fred)($| )','\1freddies\3') str
4 from dual
5 /
STR
this freddies is freddies fred freddies record
1 row selected. -
Reg Exp always returning false value
Hi,
Below is my code. I want to restrict the values to only alphabets and numbers and not special char.
But the below condition fails on a positive value also. Ex: ABCD, abcd, 1234. These should be acceptable.
Is the reg exp wrong?
private var special_char:RegExp = /^[A-Za-z0-9]*$/;
private function validateSpecialChar(inputValue:String):Boolean {
if (special_char.test(inputValue))
valid = true;
else
valid = false;
return valid;
Thanks,
ImranTry: http://stackoverflow.com/questions/9012387/regex-expression-only-numbers-and-characters
-
Reg Exp won't make a match with metacharacters?
Hi All,
I'm trying to implement a filefilter using regular expressions to allow wildcard searches. Here is the code I have so far. Works fine for a literal match, but if i enter a wildcard search (eg. abc123) it will not list any files, even though if I enter the full name for a file, it matches just fine. Anyone got any ideas because I'm just comming up blank?
thanks!
package dbmanager2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.regex.*;
* @author nkelleh
public class LotDialog
// Declare variables
private String[] dirFiles;
// Class constructor
public LotDialog(String path, String name)
// Create new file object based on path name given
File dir = new File(path);
// Assign file names to string array
dirFiles = dir.list(new stdfFilter(name));
public void printFiles()
for (String files : dirFiles)
System.out.println("File is " + files );
class stdfFilter implements FilenameFilter {
Pattern pattern;
public stdfFilter(String search)
// Replace wildcard, '*', with reg exp, '.*'
search = search.replaceAll("\\*", ".*");
search = search.replaceAll("\\?", ".");
pattern = Pattern.compile(search);
System.out.println(pattern.pattern());
public boolean accept(File dir, String name)
if (new File(dir,name).isDirectory())
return false;
else
// Return true if a match is found
Matcher matcher = pattern.matcher(dir.getName());
return matcher.matches();
}LeWalrus wrote:
Hi All,
I'm trying to implement a filefilter using regular expressions to allow wildcard searches. Here is the code I have so far. Works fine for a literal match, but if i enter a wildcard search (eg. abc123) it will not list any files, even though if I enter the full name for a file, it matches just fine. Anyone got any ideas because I'm just comming up blank?
...Try debugging your code. A good place to start is to print the following to see where things go wrong:
public boolean accept(File dir, String name)
if (new File(dir,name).isDirectory())
System.out.println("Ignoring: "+new File(dir,name));
return false;
else
Matcher matcher = pattern.matcher(dir.getName()); // shouldnt that be 'name' instead of 'dir'?
System.out.println("Accept: "+dir.getName()+"? "+matcher.matches());
return matcher.matches();
} -
Hi Folks;
I need to create a reg exp pattern with these rules :
mpexprfinal : mpexprUnit(\ OROP\ mpexprUnit)*
mpexprUnit : mp(\ AND\ mp)*minusplusexpr
minusplusexpr : "\ \(+\)\ " or "\ \(-\)\ "
mp : "[A-Z]{1}[0-9]{6}" (ex: I123456)
OROP : ","
Help me please!
Edited by: Moostiq on 2 mai 2011 16:52
Edited by: Moostiq on 2 mai 2011 16:52Hi,
I don't know of any really good way to assign names to sub-patterns in a regular expression, and then use those names in bigger expressions.
You can (sort of) do the same thing in SQL, by assigning column aliases to string literals (as in def_1, below), or concatentions of literals and previouslly defined aliases (as in def_2):
WITH def_1 AS
SELECT '\(\+|-\)' AS minusplusexpr
, '[A-Z]{1}[0-9]{6}' AS mp
, ';' AS orop
FROM dual
, def_2 AS
SELECT def_1.*
, mp || '( AND '
|| mp
|| ')*' AS mpexprunit
FROM def_1
SELECT x.*
FROM table_x x
CROSS JOIN def_2 d
WHERE REGEXP_LIKE ( x.txt
, d.mpexprunit || '('
|| d.orop
|| '|'
|| d.mpexprunit
|| ')*'
;Take this as pseudo-code. I'm not sure it will do anything. (I can't test it until you post some sample data).
If it does run, I'm not sure it will do what you want (since you haven't explained what you want).
You may find it easier just to repeat the expressions in your code. An approach like the one above is most useful when the definitions (mp, mpexprunit, and so on) change frequently.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using. I'm not sure you'll need any features that were added after Oracle 10.1, but why take a chance? -
Reg Exp confusion when searching for a '(' char
Hello,
I am trying to extract the name from the following HTML.
onclick="searchCitationAuthor('Inoue, K.', true);">I want to be able to extract 'Inoue, K.'.
My regular expression is as follows.
"\\=true\\)\">([^<]+)</a>";I need to extract from the entire line of code. I need to extract from the =true chars as this makes the Reg Exp distinctive.
I think the ')' char is confusing things.
Can anyone suggest anything?
Message was edited by:
VanJay011379
Sorry, I realize i was missing a ';' char. I thought the "\\)" was causing problems. Move on, nothing to see here LOL : )why not
String regex = "searchCitatationAuthor\\s*\\(\\s*'([^']*)'"
where is =true coming in though? -
123-reg and natemail form problem
Hi,
I am using natemail for my contact forms and hosting the site
on 123-reg. I
get an error message HTTP 405 when trying to send an email
(using the PHP
natemail form). I guess that is because of the host. Is there
an alternative
way of sending contact forms with hosts that will not allow
PHP forms?Hi bodds2013,
I found a few discussions that could help you.
http://forums.adobe.com/message/3357971#3357971 (Dated 2010 but the general guidelines should help you)
http://forums.adobe.com/message/5374622
http://forums.adobe.com/message/5110006#5110006
Thanks,
Preran -
Hi
I want to extract the first token of filename (and not the directory path) from a string like this:
D:\MIRACLE\UPLOADS\1361\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
/HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
the tokens would bed HG-ORA02 in all instances
Could you help me creating a reg expression to get the token?
best regards
MetteHi,
Whenever you have a problem, it helps if you post your sample data in a form people can use.
CREATE TABLE and INSERT statements are great; so is:
CREATE TABLE table_x
AS select 'D:\MIRACLE\UPLOADS\1361\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
AS filename, 1 as x_id FROM dual
UNION ALL SELECT 'HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
AS filename, 2 as x_id FROM dual
UNION ALL SELECT '\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
AS filename, 3 as x_id FROM dual
UNION ALL SELECT '/HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
AS filename, 4 as x_id FROM dual
;It also helps if you explain how you get the results you want from that data.
Assuming that
(a) the filename is divided, first, by '/' or '\' characters, and
(b) each of those parts may be divided into tokens by '.' or '#' characters, and that
(c) we want the first (b) part of the last (a) part:
SELECT REGEXP_SUBSTR ( REGEXP_SUBSTR ( filename
, '[^/\]*$'
, '[^.#]+'
) AS token_1
FROM table_x;Here, the inner REGEXP_SUBSTR finds the last part delimited by / or \. You can add other delimiters by putting them in the square brakets, anywhere after ^.
The outer REGEXP_SUBSTR operates on the results of the inner one. It returns the first part delimited by . or #. Again, you can add other delimiters. -
Reg: SAP Adobe form size restrictions
Hi Geeks,
Could anybody explain me about the memory restriction in sap adobe offline forms. Presently the form size is around 670kb with 3 pages. There is plan to expand this to 26 pages with 670kb * 8 .Will there be any performance issue in this case?
Regards,
Sivakaran.K.CHi Kumar,
For sure your form would be @ 5 MB and it would be a performance issue.
Since the entire file has to be processed between ECC & ADS systems you can see the processing time and its hectic.
but I have a doubt, your 3 pages file is @ 670KB..? is it any complex one...?
Well there is a bug in ADLC 8.2.X version where it keeps on adding <?templateDesigner StyleID aped3?> this tag redundantly every time you edit the form, especially when you copy paste elements with in the form. check if there is something like this in your form just in case.
The solution for this bug is Manually delete all the entries leave one for occurance. (alternatively if you search in adobe forms you can find a parser which deletes these redundant entries.)
Then upgared to latest ADLC or have respective patch.
Cheers,
Sai. -
Reg: Schedule agreement form
hello experts,
when i delete or change any line item from ME32L for schedule agreement form it will show the form in spool that line item was deleted. actually this is happening for (standard form: medruck and prog: sapfm06p). but i want to debug that form how it is showing the form with particulars of that item. when i keep break point in sapfm06p it's not stopping. the same logic i have to implement for my Z prog.
can u tell me anybody how can i debug that form.
thanks in advance.hi pammi,
To debugg a sapscript v can use the standard program --> RSTXDBUG.
Otherwise u can activate using SE71 --> Activate debugger.
Regards....
Arun.
Reward points if useful. -
Reg Adobe Interactive Form integration in WDA
Hi All,
I 've created one Interactive Adobe form named as ZADOBE having interface with same name. I used this to get Departent Name Entry. I made one ztable for storing those values entered through Adobe Form.
But, my problem is when I test the webdynpro application, it gives immediate error as below --
The URL http://xyz.vitalwires.com:/sap/bc/webdynpro/sap/zadobe/ was not called due to an error.
Here, I'd like to mention that I made wda with the name ZADOBE and saved as local object.
The complete error is --
Note
■The following error text was processed in the system DEV : WebDynpro Exception:
■The error occurred on the application server unidev_DEV_00 and in the work process 0 .
■The termination type was: RABAX_STATE
■The ABAP call stack was:
Method: CONSTRUCTOR of program CL_WD_ADOBE_SERVICES==========CP
Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/LADOBE==================CP
Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/LADOBE==================CP
Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L8STANDARD==============CP
Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L8STANDARD==============CP
Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L8STANDARD==============CP
Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L7STANDARD==============CP
Method: CONV_VIEW_INTO_VE_ADAPTER_TREE of program CL_WDR_INTERNAL_WINDOW_ADAPTERCP
Method: SET_CONTENT_BY_WINDOW of program CL_WDR_INTERNAL_WINDOW_ADAPTERCP
Method: RENDER_WINDOWS of program CL_WDR_CLIENT_SSR=============CP
Please suggest what have been left to follow...?
Thanks.
Kumar Saurav.Issue Resolved.
Kumar Saurav. -
Standard Travel Exp Booking Form Name
Hi Experts,
Could you let me know the name of the standard form available in the SAP system for the expense booking in PR05?
Please also let me know the standard form is a Smart Form or something else?
Like for PDF form Name is : PTRV_EXPENSE_FORM
Regards,Hi CSY,
Thanks for your reply, please let me know whether
1. u201CList outputu201D is a program? through which all these details are coming in a particular format when we view by pressing the u201CSimulateu201D button in PR05 if yes then
2. Can it be possible to make the changes by making a copy of the original program & make it a u201CZu201D program? & after changes
3. Whether it is possible to attach with the standard PR05? And not to a u201CZPR05u201D So that we can view the u201CZ list outputu201D (modified program of list output) in the same manner as we are viewing the original u201CList outputu201D
4. If yes, please let me know in detail.
Regards, -
Strange behavior when searching a phrase using reg exp and dynamic sql
Hi,
I have a strange issue while using dynamic sql for an apex page. I have a requirement to search a string in the database column which is entered by user on a page item. The search process should search the whole phrase only.
I have a query generated dynamically in the back end and use it in a cursor in the stored procedure
SELECT t.group_cn , t.group_desc, t.group_type, t.partner_organization_id, t.partner_organization
FROM vr_idm_group t WHERE regexp_like(t.group_desc,'(^|\W)HR Selection & Assignment(\W|$)', 'i')The pl sql code with the dynamic sql statements are below.
IF p_search_process NOT in ('PARTNER') THEN
OPEN v_cursor FOR v_sql;
ELSE
OPEN v_cursor FOR v_sql USING p_search_id;
END IF;
LOOP
FETCH v_cursor INTo v_obj.group_cn, v_obj.group_desc, v_obj.group_type, v_obj.partner_organization_id,
v_obj.partner_organization, v_obj.match_count;
EXIT WHEN v_cursor%NOTFOUND ;
v_search_array.extend;
v_search_array(v_search_array.last) := v_obj;
dbms_output.put_line(v_sql);
END LOOP;The search works fine if the search string does not contain any special character like &,- etc.
However, if the search string contains any special character, it does not return any thing. This strange issue happens only if I call the procedure from the apex page and the search string contains a special character. (please note that the procedure works fine even from apex if the string does not have a special character). When I debugged this, found that, the cursor does not fetch any rows (it is supposed to fetch two rows) for unknown reason. When I run the query separately, it returns the two rows (in which the column group_desc contains the search string "HR Selection & Assignment") as desired. Also, when I test the procedure in the back end (PLSQL developer), it works fine.
Any idea, what is causing this strange behaviour?
Advance thanks.
Regards,
Natarajani don't see anything about a dataProvider. you're assigning a source for a scrollpane. scrollpane's don't have a dataProvider property.
anyway, other than arrayRun always being false when that last if-statement executes, what's the problem? doesn't that movieclip display when that 2nd branch of the last if-statement executes (assuming instance is defined correctly etc)?
Maybe you are looking for
-
Missing folder in list view. Mac OSX 10.4.11
I have an external Firewire Hard Drive with 10 folders on it. One of the folders contains around 100GB of video files. This folder does not appear in the list view. All the other folders appear as normal. In ccon or column view the folder is there. I
-
I have updated to ios 7 as has my daughter. Now when I send her a text all that shows up is her phone number or part of the number, not her name. I'm not even sure she is getting the texts because she hasn't responded at all. She is usually very prom
-
Recovery Disk Error : cannot read from source file or disk HOW TO FIX ISSUE
I have had my satellite L655-S5096 for some time now.. I had to switch out hard-drives the other day and installed windows 7 home on it from my own disk. I tried to download all the drivers needed, but the graphics and wifi drivers never worked, so
-
My Unlimited Plan changed without my authorization!
I went online to place an insurance claim on my phone only to discover that the insurance I have always had on all my phones with you guys is no longer on my plan. When I called to find out what was going on and why the insurance was removed I was to
-
How can i close internet explorer to download flash
how can I close internet expllorer to download flash