Need a regular expression for URL
Regular expression: ^(udp|norm)://(?:(?:25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)(?(?=\\.?\\d)\\.)){4}:(6553[0-5]|655[0-2][0-9]\\d|65[0-4](\\d){2}|6[0-4](\\d){3}|[1-5](\\d){4}|[1-9](\\d){0,3})$
Source: udp://125.3.4.121:23456
Getting error:java.util.regex.PatternSyntaxException: Unknown inline modifier near index 54
^(udp|norm)://(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(?=\.?\d)\.)){4}:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})$
paulcw wrote:
I can't help wondering if a simpler solution would involve creating a java.net.URL object, passing it the string to be checked, and let URL do the parsing and an initial pass at checking the syntax. Then you could query URL for individual components for further checking (e.g., getting the transfer type to make sure it's one of the kinds you want). This approach would probably be more self-documenting, if nothing else.Nice idea, but java.net.URL doesn't actually do much work at all. It basically takes the protocol part, looks up a handler for it, and delegates everything else to that. The handlers themselves are down in the sun packages (or whatever your Java impl is) and since there isn't one for the OPs protocol, he'd have to write and register his own anyway, which kind-of negates the entire purpose of leveraging it.
@OP: Paul's suggestion can still be of use. Apache, Codehaus and the like will have written their own protocol handlers, it's worth grabbing the source code for, say, Apache HttpClient, and seeing if they've got anything useful in there. Then again, who's to say that what's a valid URL for this 'norm' protocol, other than whoever designed the protocol?
Similar Messages
-
Need a regular expression for the text field
Hi ,
I need a regular expression for a text filed.
if the value is alphanumeric then min 3 char shud be there
and if the value is numeric then no limit of chars in that field.[0-9].
Any help is appriciated...
thanks
bharathi.Try the following in the change event:
r=/^[a-z]{1,3}$|^\d+$/i;
if (!r.test(xfa.event.newText))
xfa.event.change="";
Kyle -
Regular expressions for URLs to match extensions
I am working on a simple method that will assign a specific extension
(e.g. ".jsp", ".php", ".cfm", etc.) to the end of a URL if it doesn't
find anything marking a valid extension, however, I do not want to add
an extension if one is found.
Consider my code:
import java.util.regex.Pattern;
public static final String urlEndSlashPattern = "/?";
public static final String urlQSPattern = "\\??([a-zA-Z0-9\\-_\\.]
+=[^&]*&?)*";
public static final String urlAnchorPattern = "#[^#]*$";
public static void addExtToUrl(String url, String myExt, String[]
exts) {
StringBuffer sb = new StringBuffer();
boolean hasExt = false;
for (int i = 0; i < exts.length; i++) {
sb.append(".").append(exts).append(urlEndSlashPattern).append(urlQSPatte�rn).append(urlAnchorPattern);
if (Pattern.matches(sb.toString(), url)) {
hasExt = true;
sb = new StringBuffer();
if (!hasExt) {
url += "." + myExt;
The issue I want to bring up is the regular expression pattern I'm
using appears to fail. I want to check and see if the URL I provide
ends with a valid extension, followed by optional "/" or a query
string or an anchor or any combination of these.
Like say if I have
http://www.blah.com/index.html
Then don't add the ".jsp" extension
But if I have
http://www.blah.com/registration/
Then I *want* to add the ".jsp" extension:
http://www.blah.com/registration.jsp
Or if I have:
http://www.blah.com/registration/?foo=bar#baz
Then it needs to change to
http://www.blah.com/registration.jsp?foo=bar#baz
But if I have
http://www.blah.com/registration/index.php?foo=bar#baz
Then I do *not* add the ".jsp" extension.
Hope that makes sense now. Bottom line is that the pattern above
doesn't seem to work. Ideas?
ThanksOk, just for fun, let's try it.
URL: http://www.blah.com/?bar=baz#anchor
Absolutely valid URL and something possible (remember, Balus, this is from a database entry, thus, it can be anything at all!)
Let's split onto the last /
Your last entry will be
?bar=baz#anchor
So if I re-insert the .jsp that it would not find I get
http://www.blah.com/.jsp?bar=baz#anchor
INVALID URL
Now let's try this one, BalusC:
http://www.blah.com/index.jsp?forwardURL=http://www.wee.com/gotcha_balus/
Now we split according to the ... last /
http://www.blah.com/index.jsp?forwardURL=http://www.wee.com/gotcha_balus.jsp
Valid URL, but possibly wrong when the query string value for "forwardURL" is read, thus, making the URL ultimately wrong.
Two examples that show that splitting by the last / can't work here. -
Hi everyone,
I have a question about regular expressions.
Let's say I want my program to extract last 10-digits from any URL that will be found (every found URL will end up on 10digit number!) and insert that number in the middle of other URL.
Would anyone tell me please how to do that?
Thank youI am not sure how to do that either...
Actually I just figured out that there is no garantee that the URL will be ended on 10-digit number.
Ok, my program is meant to search for the movie info on Yahoo (user enters keyword to search and chooses either 'title', 'actor', 'trailer', 'review' in drop-down menu). After the 'search' button is clicked the appropriate page is supposed to be found.
For example, if the user types in 'shrek' and chooses 'trailer', the result is supposed to be this link http://movies.yahoo.com/movie/1808405861/trailer and not the
following ones:
http://movies.yahoo.com/mv/search?p=shrek
or
http://movies.yahoo.com/shop?d=hv&cf=info&id=1808405861
So in my program the line for the 'title' search is
url = "http://movies.yahoo.com/mv/search?type=all&p=";and it works for the titles. I thought if the found link has 10 -digit number on the end I can somehow 'catch' that number and insert into another link -so the page with trailers would be pulled up (it's an ID number in yahoo database) .
But now since I am not sure if 10-digit number is going to be in the found link at all, I have no idea how to 'catch' that number.
Does anyone have any ideas for my case? -
Regular Expression For Dreamweaver
I still haven't had the time to really become a professional when it comes to regular expressions, and sadly I am in need of one an finding it difficult to wrap my head around.
In a text file I have hundreds of instances like the following:
{Click here to visit my website}{http://www.adobe.com/}
I need a regular expression for Dreamweaver that I can run within the "Find and Replace" window to switch the order of the above elements to:
{http://www.adobe.com/}{Click here to visit my website}
Can anyone provide some guidance? I'm coming up short due to my lack of experience with regular expressions.
Thank you in advance!So you have a string that starts { and goes until the first }. Then you have another string exactly the same. And you want to swap them. I'm not making any assumption that the second one has to look like a URL (that's a whole other minefield, but perhaps you could do something simple like it must start with http).
You don't specify how your text file is divided up, have you got this as a complete line to itself, or is it just a huge block of text? Preferably as individual lines.
I don't have Dreamweaver, but this worked for me in Notepad++
Find: ^{(.*?)}{(.*?)}$
Replace with: {\2}{\1}
My file looked like this:
{Click here to visit my website}{http://www.adobe.com/}
{some other site}{http://www.example.com/foo}
And doing a Replace All ended up like this:
{http://www.adobe.com/}{Click here to visit my website}
{http://www.example.com/foo}{some other site} -
Regular expression for recognizing all tables in a sql statement
Hi all
I need a regular expression for recognizing all the tables bane in a geberic statement.
Unlikely i need a regular expression that manage also inner join .I 'm sorry but this matter is new for me and i cannot find any usefull help in the web.
RegardsIf you insist it should be something like:
"SELECT ([A-Z0-9_]+)[.][A-Z0-9_]+(,([A-Z0-9_]+)[.][A-Z0-9_]+)* FROM (([A-Z0-9_]+)[.][A-Z0-9_]+) INNER JOIN (([A-Z0-9_]+)[.][A-Z0-9_]+) ON .+" plus spaces etc... Yes it's for this kind of statements only.
But SQL parser is better because anyway you'll need to at least remove duplicates from founded names... -
Re:java regular expression for website
Hi All,
I am using jdeveloper 11.1.2.3.0
My requirement is that I have a website attribute I need the regular expression for the website attribute
to display the format www.google.com www.oracle.com.
Thanks,
SandeepHi Sandeep,
you can use the below code for website validation.
<af:inputText label="" id="time" simple="true" value="" contentStyle="width:100px;" maximumLength="100">
<af:validateRegExp pattern="^www[.][a-z]{1,15}[.](com|org)$"
messageDetailNoMatch="Website must be like www.google.com"
hint="Website Format: www.google.com"/>
</af:inputText>
as per your requirement you can change the pattern.
Thanks
Prabhat -
How to write the regular expression for Square brackets?
Hi,
I want regular expression for the [] Square brackets.
I have tried to insert in the below code but the expression not validate the [] square brackets.
If anyone knows please help me how to write the regular expression for [] Square brackets.
private static final Pattern DESC_PATTERN = Pattern.compile("({1}[a-zA-Z])" +"([a-zA-Z0-9\\s.,_():}{/&#-]+)$");Thanks
RaghavSince square brackets are meta characters in regex they need to be escaped when they need to be used as regular characters so prefix them with \\ (the escape character).
-
What is the regular expression for the end of a story?
Forgive me if this is wrong forum for asking this, but I'm trying to use the Find command using GREP and I need to know the regular expression for the end of a story. (Or, the last character of a story.) Thanks in advance.
I'd try search for .\z (that's a dot in front) which ought to find the very last character in the story, and replace with $0 and your additional text.
You know you can use a keyboard shortcut to move your cursor to the end of any story, right? Ctrl + End on Windows, Cmd + End, I think, on Mac. Unless you want to do this to every single story in the document, I would think you might be just as well off to put your text on the clipboard, put the cursor in the story and hit the key combo followed by Ctrl/Cmd + V to paste. -
Regular Expression for PathName???
Anyone have a "ready to go" regular expression for detecting a pathname?
for example I need to detect the following:
myfile.txt
./myfile.txt
../my-file.ini
/home/my-home/myFile.foo
etc.
Now, in a perfect world, it could also do Windows (or ANY OS for that matter) pathnames (though this is not terrbibly important for my case at least).
TIA,
/mimport java.util.regex.*;
* @author Ian Schneider
public class FileRegex {
static Pattern pattern;
/** Creates a new instance of FileRegex */
public FileRegex() {
public Pattern getPattern() {
if (pattern == null) {
pattern = Pattern.compile("([\\/]?(\\w+|\\.|\\.\\.)[\\/])*(\\w+)\\.?(\\w+)?");
return pattern;
public String[] parts(String path) {
Matcher m = getPattern().matcher(path);
if (m.find()) {
return new String[] { m.group(1),m.group(3),m.group(4) };
return null;
public boolean matches(String path) {
return getPattern().matcher(path).matches();
public static final void main(String[] args) throws Exception {
FileRegex regex = new FileRegex();
String[] files = {
"myfile.txt",
"../myfile.txt",
"./myfile.txt",
"/a/b/c/myfile.txt",
"/a/../myfile.txt",
"myfile"
for (int i = 0, ii = files.length; i < ii; i++) {
System.out.println( files[i] + " match " + regex.matches(files));
String[] pieces = regex.parts(files[i]);
if (pieces != null)
System.out.println(" path : " + pieces[0] + " file : " + pieces[1] + " ext : " + pieces[2]);
I will leave it to you as an excercise to add support for spaces in path names, different separator characters, etc.. -
Regular Expression for IPAddress
Hello members.....
I am a new member to this forum
I am in need of the Regular Expression for IPAddress...
"[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"....is the expression i wrote..But it is taking 0.0.0.0 as a valid IPAddress. (0.0.0.0 is not a valid IPAddress)
Please reply....awaiting
RajeshwarI am in need of the Regular Expression for
IPAddress...
"[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"
....is the expression i wrote..But it is taking
0.0.0.0 as a valid IPAddress. (0.0.0.0 is not a valid
IPAddress)Your regex matches "999.999.999.999", which (of course) isn't a vaild IP address as well.
This one is closer, but still allows 0.0.0.0:
\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\bBut why not roll your own method which checks an IP address? -
Request some help, over procedure's performance uses regular expressions for its functinality
Hi All,
Below is the procedure, having functionalities of populating two tables. For first table, its a simple insertion process but for second table, we need to break the soruce record as per business requirement and then insert into the table. [Have used regular expressions for that]
Procedure works fine but it takes around 23 mins for processing 1mm of rows.
Since this procedure would be used, parallely by different ETL processes, so append hint is not recommended.
Is there any ways to improve its performance, or any suggestion if my approach is not optimized? Thanks for all help in advance.
CREATE OR REPLACE PROCEDURE SONARDBO.PRC_PROCESS_EXCEPTIONS_LOGS_TT
P_PROCESS_ID IN NUMBER,
P_FEED_ID IN NUMBER,
P_TABLE_NAME IN VARCHAR2,
P_FEED_RECORD IN VARCHAR2,
P_EXCEPTION_RECORD IN VARCHAR2
IS
PRAGMA AUTONOMOUS_TRANSACTION;
V_EXCEPTION_LOG_ID EXCEPTION_LOG.EXCEPTION_LOG_ID%TYPE;
BEGIN
V_EXCEPTION_LOG_ID :=EXCEPTION_LOG_SEQ.NEXTVAL;
INSERT INTO SONARDBO.EXCEPTION_LOG
EXCEPTION_LOG_ID, PROCESS_DATE, PROCESS_ID,EXCEPTION_CODE,FEED_ID,SP_NAME
,ATTRIBUTE_NAME,TABLE_NAME,EXCEPTION_RECORD
,DATA_STRUCTURE
,CREATED_BY,CREATED_TS
VALUES
( V_EXCEPTION_LOG_ID
,TRUNC(SYSDATE)
,P_PROCESS_ID
,'N/A'
,P_FEED_ID
,NULL
,NULL
,P_TABLE_NAME
,P_FEED_RECORD
,NULL
,USER
,SYSDATE
INSERT INTO EXCEPTION_ATTR_LOG
EXCEPTION_ATTR_ID,EXCEPTION_LOG_ID,EXCEPTION_CODE,ATTRIBUTE_NAME,SP_NAME,TABLE_NAME,CREATED_BY,CREATED_TS,ATTRIBUTE_VALUE
SELECT
EXCEPTION_ATTR_LOG_SEQ.NEXTVAL EXCEPTION_ATTR_ID
,V_EXCEPTION_LOG_ID EXCEPTION_LOG_ID
,REGEXP_SUBSTR(str,'[^|]*',1,1) EXCEPTION_CODE
,REGEXP_SUBSTR(str,'[^|]+',1,2) ATTRIBUTE_NAME
,'N/A' SP_NAME
,p_table_name
,USER
,SYSDATE
,REGEXP_SUBSTR(str,'[^|]+',1,3) ATTRIBUTE_VALUE
FROM
SELECT
REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,t2.COLUMN_VALUE) str
FROM
DUAL t1 CROSS JOIN
TABLE
CAST
MULTISET
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
AS SYS.odciNumberList
) t2
WHERE REGEXP_SUBSTR(str,'[^|]*',1,1) IS NOT NULL
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
Many Thanks,
ArpitRegex's are known to be CPU intensive specially when dealing with large number of rows.
If you have to reduce the processing time, you need to tune the Select statements.
One suggested change could be to change the following query
SELECT
REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,t2.COLUMN_VALUE) str
FROM
DUAL t1 CROSS JOIN
TABLE
CAST
MULTISET
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
AS SYS.odciNumberList
) t2
to
SELECT REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,level) str
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
Before looking for any performance benefit, you need to ensure that this does not change your output.
How many substrings are you expecting in the P_EXCEPTION_RECORD? If less than 5, it will be better to opt for SUBSTR and INSTR combination as it might work well with the number of records you are working with. Only trouble is, you will have to write different SUBSTR and INSTR statements for each column to be fetched.
How are you calling this procedure? Is it not possible to work with Collections? Delimited strings are not a very good option as it requires splitting of the data every time you need to refer to. -
Hi Everyone,
I need help with regular expression for following scenario .
If any of the DBCC command is run against sql server i want it to be captured . Something like if it starts with DBCC it should be captured .
For instance following is expression for
DBCC CheckDB : part="dbcc checkdb", rgxp="(\s|;|^)dbcc\scheckdb\s?\((((to[a-z0-9_\$\#\.\@])|(t[abcdefghijklmnpqrstuvwxyz0-9_\$\#\.\@])|([abcdefghijklmnopqrsuvwxyz]))[a-z0-9_\$\#\.\@]*)\s?\)(\s|;|$)"
But instead of writing expression for all DBCC commands is there any way to write a regular expression say if DBCC i want it to be captured .
Thanks
Suhas VallalaHi Suhas,
As Olaf said, regular expressions is not supported in SQL Server. To trace the DBCC event, you can use the SQL Sever Profiler, just tick the Security Audit--> Audit DBCC Event. You can set up a trace in the profiler by following the below tutorial.
SQL SERVER – Introduction to SQL Server 2008 Profiler
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support -
Hi All,
What should be the regular expression for string MT940_UB_*.txt and MT940_MB_*.txt to be used as filename inSFTP sender channel in PI 7.31 ??
If any one has any idea on this please let me know.
Thanks
NehaHi All,
None of the file names suggested is working.
I have tried using - MT940_MB_*\.txt , MT940_MB_*.*txt , MT940*.txt
None of them is able to pick this filename - MT940_MB_20142204060823_1.txt
Currently I am using generic regular expression which picks all .txt files. - ([^\s]+(\.(txt))$)
Let me know ur suggestion on this.
Thanks
Neha Verma -
How to form a regular expression for matching the xml tag?
hi i wanted to find the and match the xml tag for that i required to write the regex.
for exmple i have a string[] str={"<data>abc</data>"};
i want this string has to be splitted like this <data>, abc and </data>. so that i can read the splitted string value.
the above is for a small excercise but the tagname and value can be of combination of chars/digits/spl symbols like wise.
so please help me to write the regular expression for the above requirementyour suggestion is most appreciable if u can give the startup like how to do this. which parser is to be used and stuff like that
Maybe you are looking for
-
Can't prevent iTunes from starting when I connect my iPhone
I primarily connect my iPhone 4 to an iMac at home, on which pretty much all of my content is stored. It's set up to sync wirelessly. Until recently, I synced my calendar and contact data to Outlook on my work computer, which is a PC running Window
-
Optical out (toslink) woes
Hi, I've been tryin three different Airport Express basestation all with the same result: The optical output that connects to external speakers or digital amps does not seem to work. I tried connecting a B&W Zeppelin and my old iPod Hi-Fi. No chance.
-
Hi All, being a complete Java(TM) newbie here is a very silly question. After reading the "Java Code Conventions" (see http://java.sun.com/docs/codeconv/) and studying here and there the Java core library source code (see src.zip on your SDK installa
-
Price per minute of Flash animation?
Hi, I need to create 2 minutes of animated info graphics in Flash. What is the general formula for price per minute of Flash animation? I know it varies, though this would be high-end animation requiring lots of things to be animated, such as bar gra
-
Hi. I have another problem. I try to send a message to a topic destination, but it doesn't persist (dest. is always empty). No errors and the log and seems to be fine. I post my JAVA code, some metrics and a log after starting the JAVA class. "For pe