I want to use regex to remove after closing parenthesis. Any help?
Original:
CREATE TABLE "EMP"
( "EMPNO" NUMBER(4,0) NOT NULL ENABLE,
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"SAL" NUMBER(7,2),
"DEPTNO" NUMBER(2,0)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
;
I want
CREATE TABLE "EMP"
( "EMPNO" NUMBER(4,0) NOT NULL ENABLE,
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"SAL" NUMBER(7,2),
"DEPTNO" NUMBER(2,0)
)
;
you could use something like:
Regex.Replace(str, #"\)\s*\)[^;]*", ")\n)");
let me know if its working...
Try this:
string less = Regex.Replace(str, "^([^)]*).*", "$1);");
Related
How to remove certain words like DUM or PRJ from begging of string if exists and then split a string based on character _ and take the second part .
For example , if we take
DUM_EI_AO_L_5864_Al Meena Tower I need to get answer as AO and from EI_AE_L_5864_Al radha Tower as AE
Replace the prefixes you want to remove, then find the index of the first and second underscores and then find the substring between those two separators:
Oracle Setup:
CREATE TABLE your_table ( value ) AS
SELECT 'DUM_EI_AO_L_5864_Al Meena Tower' FROM DUAL UNION ALL
SELECT 'EI_AE_L_5864_Al radha Tower' FROM DUAL
Query:
SELECT value,
SUBSTR( replaced_value, first_separator + 1, second_separator - first_separator - 1 )
AS second_term
FROM (
SELECT value,
replaced_value,
INSTR( replaced_value, '_', 1, 1 ) AS first_separator,
INSTR( replaced_value, '_', 1, 2 ) AS second_separator
FROM (
SELECT value,
REPLACE(
REPLACE(
value,
'PRJ_'
),
'DUM_'
) AS replaced_value
FROM your_table
)
)
Output:
VALUE | SECOND_TERM
:------------------------------ | :----------
DUM_EI_AO_L_5864_Al Meena Tower | AO
EI_AE_L_5864_Al radha Tower | AE
Query 2:
You can also use a regular expression:
SELECT value,
REGEXP_SUBSTR( value, '(DUM_|PRJ_)?.*?_(.*?)_', 1, 1, NULL, 2 ) AS second_term
FROM your_table
Output:
VALUE | SECOND_TERM
:------------------------------ | :----------
DUM_EI_AO_L_5864_Al Meena Tower | AO
EI_AE_L_5864_Al radha Tower | AE
db<>fiddle here
I am not a C# programmer & need help. I have some questions:
when I have the string text='My car is nice', then what would be the output of the following lines:
(1) text.Substring(1,1);
(2) text.Substring(6,1);
(3) text.Substring(1,4).Replace('c','a');
(4) text.Substring(1,10).Replace('a','b').Replace(' ','t');
My conclusions are:
(1) 'y'
(2) ' is nice M' <== here, I started from 6 until 1 (or do I need to swap 1&6?)
(3) 'y c'
(4) 'ytcbrtist' <== here I replaced a with b & the space lines with t
I hope someone can help.
Best regards,
If you look at the doc of String.Substring Method (Int32, Int32) it says that:
public string Substring(
int startIndex,
int length
)
Then:
(1) text.Substring(1,1);
(2) text.Substring(6,1);
(3) text.Substring(1,4).Replace('c','a');
(4) text.Substring(1,10).Replace('a','b').Replace(' ','t');
(1) 'y' // Indice 1 length 1
(2) ' ' // Indice 6 length 1
(3) 'y aa' // Indice 1 length 4 and replacements
(4) 'ytcbrtistn'// Indice 1 length 10 and replacements
See it live
1)'y' OK
2)' ' The sixth character is 'r'. And the next one is space ' '.
3)'y aa' . You are taking 4 chars starting from first. It's 'y ca' . Later You replace c with a.
4)'ytcbrtistn' . You take 10 chars starting from 2nd one. 'y car is n' . You replace a with b -> 'y cbr is n' . Later replace space with t.
I am trying to validate any real number in different formats using one regex rule in .NET. The formats I mean are the following:
Dots (thousands) and comma (decimal)
123 ; 1.234.567 ; 12.345.678 ; 123.456.789 ; 1.234.567,89 ; 1.234,56789 ; 1,2 ; 0,123
Commas (thousands) and dot (decimal)
1,234,567 ; 12,345,678 ; 123,456,789 ; 1,234,567.89 ; 1,234.56789 ; 1.2 ; 0.123
White space (thousands) and dot or comma (decimal)
1 234 567 ; 12 345 678 ; 123 456 789 ; 1 234 567,89 ; 1 234 567.89 ; 1 234,56789 ; 1 234.56789
I know a bit more that the basics about regex, so I have done this. No success so far.
(^|\s)(-|\+|±|\+/-)?(?:(([1-9]{1,3})([,]\d{3})*|[0]?)([\.]\d+)?)|(?:(([1-9]{1,3})([\.]\d{3})*|[0]?)([,]\d+)?)|(?:(([1-9]{1,3})([\s]\d{3})*|[0]?)([\.|,]\d+)?)(\s|$)
Can any one help me or link me to the solution if it is out there?
Well, this may not be the optimal regex:
^\d*$|^(?:\d{1,3}(?:\.\d{3})*(?:,\d{1,5})?)$|^(?:\d{1,3}(?:,\d{3})*(?:\.\d{1,5})?)$|^(?:\d{1,3}(?: \d{3})*(?:[,.]\d{1,5})?)$
But it does the job. I'll look how to make a better one in a near future. Here's a Live Demo
If your input is not that dirty (ie: once you have a space as a thousand separator you don't get dot then comma, not like 1 032,354.12) you can use this simple version:
^\d{1,3}(?:[., ]\d{3})*(?:[.,]\d{1,5})?$
Which means:
\d{1,3} <= start with 1 to 3 digit;
(?:[., ]\d{3})* <= thousand separator with 3 digit after repeated 0 to n times;
(?:[.,]\d{1,5})? <= decimal separator with 1 to 5 digit after it, 0 or 1 time.
I need a RegEx to match both Integer values as well as Float numbers.
and i want to use it using *Regular Expression Validator *
What should be Valid:
.1
.12
1.2
1.23
12.3
12.34
1
12
What should be Invalid:
.123(this value is having more then 2 decimal values)
1.234(this value is having more then 2 decimal values)
What i exactly want is to take values from 0 to 99.99 only in TextBox(MaxLength=5) Control in ASP.Net with C#.
you want a regex like this
^(?:\d{1,2})?(?:\.\d{1,2})?$
here the non capturing group (?:\d{1,2}) will check for values between 0 - 99.
this has been made optional with ? because values like .12 , .2 are permitted.
demo here : http://regex101.com/r/oW7rF4
You can implement a check like this:
String string = "1.23";
if(
string.match(/^\d+$/) || // for "123", "456"
string.match(/^\d+\.\d{1,2}$/) || // for "123.45", "4.5"
string.match(/^\.\d{1,2}$/) ) // for ".45", ".8"
// do something
else
// do something else
Note: This is a pseudo-code (or whatever you call it), you can convert it to your language.
(^\d{1,2}$)|(^\d{0,2}[.]\d{1,2}$)
(^\d{1,2}$) is for INT
[0 , 1 , 12 , 99]
(^\d{0,2}[.]\d{1,2}$) is for FLOAT
[.1 , .12 , 1.2 , 1.23 , 12.3 , 12.34 , .99 , 99.99]
I have this RegEx for C# ASP.NET MVC3 Model validation:
[RegularExpression(#"[0-9]*\,?[0-9]?[0-9]")]
This works for almost all cases, except if the number is bigger than 100.
Any number greater than 100 should show error.
I already tried use [Range], but it doesn't work with commas.
Valid: 0 / 0,0 / 0,00 - 100 / 100,0 / 100,00.
Invalid (Number > 100).
Not sure if zero's are only optional digits at the end but
# (?:100(?:,0{1,2})?|[0-9]{1,2}(?:,[0-9]{1,2})?)
(?:
100
(?: , 0{1,2} )?
|
[0-9]{1,2}
(?: , [0-9]{1,2} )?
)
Zero's only option at end
# (?:100|[0-9]{1,2})(?:,0{1,2})?
(?:
100
| [0-9]{1,2}
)
(?: , 0{1,2} )?
And, the permutations for no leading zero's except for zero itself
# (?:100(?:,0{1,2})?|(?:0|[1-9][0-9]?)(?:,[0-9]{1,2})?)
(?:
100
(?: , 0{1,2} )?
|
(?:
0
|
[1-9] [0-9]?
)
(?: , [0-9]{1,2} )?
)
# (?:100|0|[1-9][0-9])(?:,0{1,2})?
(?:
100
|
0
|
[1-9] [0-9]
)
(?: , 0{1,2} )?
Here's a RegEx that matches your criteria:
^(?:(?:[0-9]|[1-9]{1,2})(?:,[0-9]{1,2})?|(?:100)(?:,0{1,2})?)$
(Given your use case, I have assumed that your character sequence appears by itself and is not embedded within other content. Please let me know if that is not the case.)
And here's a Perl program that demonstrates that RegEx on a sample data set. (Also see live demo.)
#!/usr/bin/env perl
use strict;
use warnings;
while (<DATA>) {
chomp;
# A1 => An integer between 1 and 99, without leading zeros.
# (Although zero can appear by itself.)
#
# A2 => A optional fractional component that may contain no more
# than two digits.
#
# -OR-
#
# B1 => The integer 100.
#
# B2 => A optional fractional component following that may
# consist of one or two zeros only.
#
if (/^(?:(?:[0-9]|[1-9]{1,2})(?:,[0-9]{1,2})?|(?:100)(?:,0{1,2})?)$/) {
# ^^^^^^^^A1^^^^^^ ^^^^^A2^^^^ ^B1 ^^^B2^^
print "* [$_]\n";
} else {
print " [$_]\n";
}
}
__DATA__
0
01
11
99
100
101
0,0
0,00
01,00
0,000
99,00
99,99
100,0
100,00
100,000
100,01
100,99
101,00
Expected Output
* [0]
[01]
* [11]
* [99]
* [100]
[101]
* [0,0]
* [0,00]
[01,00]
[0,000]
* [99,00]
* [99,99]
* [100,0]
* [100,00]
[100,000]
[100,01]
[100,99]
[101,00]