Regex expression for extracting whole numbers?
I would like to ask, how can I modify the code below, so it only returns int values inside the specific string, >100 which is a whole number.
The code below returns the following strings = 2525, 130, 129s, MH350s, from which '2525' is incorrect.
The value '2525' is extracted from '97.2525', which is a decimal number and should only extract value greater than 100, which is whole integer, not decimal numbers. Is their a way to
extract whole numbers using the regex expression.
public class Program
public static void Main()
// An example collection of your input
var input = "ASW+90s, N+20s, 97.2525, M45s, 130.5, +129s, 48E. MH350s";
var re1 = new Regex(@"^(\d+)[sS]$");
foreach(var match in Regex.Matches(input,@"\w*[1-9]\d{2,}\w*"))
// Output each match
Console.WriteLine(match);
any advice further, would be very much appreciated. Thank you
You've already asked this question in the forums and several people provided the RE that you need to do it right. Your RE is for integers, not fixed point values.
I replied to your original post and gave you the exact RE that parses the strings like you wanted. If you use that code then you'll get the results you want. The only piece missing now is that you are breaking up a single string into substrings for
parsing. To do that use
String.Split to split the string at the commas. The result is an array of values without the commas. Using the previous code you end up with this:
var inputs = input.Split(',');
var numbersGreaterThan100 = from i in ExtractNumbers(inputs) where i > 100 select I;
Michael Taylor
http://blogs.msmvps.com/p3net
Similar Messages
-
Use regular expressions to extract .llb filename from path
I am trying to be clever (always a dangerous thing) and use a regular expression to extract the name of a library from a filepath converted to a string. Whilst I appreciate there are other ways to do this, regex would appear to be a very powerful neat way, should I be able to get it to work.
i.e if I have a string of the type, C:\applications\versions\library.llb\toplevel.vi, I want to be able to extract library.llb from the string, given that it will be of variable length, may include numbers & spaces and may be within a file hierarchy of variable depth. In other words, I want to extract the portion of the string between the last \ that ends with .llb
The best I have managed so far, is \\+.*llb which returned everything minus the drive letter and the toplevel.vi
Can anyone help me achieve this, or am i better using an alternative method (e.g filepath to array string, search for .llb)
Thanks
Matt
Solved!
Go to Solution.Hi Matt,
attached you'll find two other options.
Mike
Message Edited by MikeS81 on 04-13-2010 01:30 PM
Attachments:
Path.PNG 7 KB -
Regular Expression for multiline response from a device
Hi,
I am trying to have a regular expression in java for a response (example response is )
Freq Table Info:
# freqs = 12
# trackers = 1 (LF), 1 (HF)
fmin = 300000 Hz
fsplit = 7000000 Hz
fmax = 150000000 Hz
updates = 1
Freq Table:
Slot | Mode | Description
-----|------|---------------------------------------------------------
0 | FUND | 400000 ( 400000
1 | FUND | 13560000 ( 13560000) Hz, tracking = True
Need to match this response and extract 400000 and 1356000 , stuck at mot being able to match the response. I tried [\\w]+[\\W]+ as well as \\w , dont think they work well enough, also tried testing on http://www.iowacomputergurus.com/free-products/regular-expression-tester.aspx, dont think am on the money yet. Can somebody please give any pointers or suggestions.
Thanks for your time.PaddyK54 wrote:
Hi,
I am trying to have a regular expression in java for a response (example response is )
Freq Table Info:
# freqs = 12
# trackers = 1 (LF), 1 (HF)
fmin = 300000 Hz
fsplit = 7000000 Hz
fmax = 150000000 Hz
updates = 1
Freq Table:
Slot | Mode | Description
-----|------|---------------------------------------------------------
0 | FUND | 400000 ( 400000
1 | FUND | 13560000 ( 13560000) Hz, tracking = True Need to match this response and extract 400000 and 1356000 , Well, given that input, your matches both are:
- made of two or more digits,
- followed by one or more spaces,
- followed by an opening parentheses.
So the regex \d{2,}(?=\s+\()would uniquely identify 400000 and 1356000 (with the example input you posted, which I know little about!). For all I know, other input may have opening parenthesis on other location in your string, which will break the regex.
For example, what if the following line occurs in your input:
# trackers = 123456 (LF), 1 (HF)
You see how that breaks my suggested regex? -
How do I set a form field to accept whole numbers only?
I am using Acrobat X.
I have a number of fields in a form that are used in a variety of calculations. It is the nature of these fields that they need to contain whole numbers only, no decimals.
On the "Format" tab, I have set the field format to "Number" and the number of decimal places to "0"
On the "Validate" Tab I have set the "Field Value is in Range" "From 0", "To 999"
This is to ensure that the field can only contain a maximum of a three digit number.
But this still allows the user to enter decimal places. This messes up my calculations so I want to limit the user's input to whole numbers.
How do I do that?
Thanks!
SteveI apologize for being dense but I really do not know how to apply your solution. Taking the path you suggested there is nothing under Tools>Document Processing relating to Java scripts.
I presume that I have to save this part somewhere in Acrobat:
// Document-level function
function triDigKS() {
// Get all that is currently in the field
var val = AFMergeChange(event);
// Reject entry if anythig but digits
event.rc = AFExactMatch(/\d{0,3}/, val);
And then use the call out:
// Custom Keystroke script
triDigKS();
Somewhere else but I don't know where thos two places are. Do I use the callout in the validation tab, or somewhere else?
Thanks
Steve -
How do you add the language of the dictionary in pages for the whole document?
How do you add the language of the dictionary in pages for the whole document. When I add the british language it does not stay ON for the whole document. It goes back to "none"???? I am using pages 09 version 4.1 (923).
This is a feature of Numbers. If you repost on the iWork forum you may get more information.
-
Extraction of Numbers from string in oracle
Dear All,
I have a AplhaNumeric field in my source table which holds the string with numbers and caharcters .i need to extract only numbers and to load into the target table which of number type.
can any one suggest me about how to do this?
regards
kumarHi ,
I have a table called smitems with column smitmqtyremarks which holds alpha numeric characters .nearly 180 records exists in this table.
i need extract numbers for this field and load into my target tables.
here i am giving sample rows for this field :
smitmqtyremarks
13 قطعة
4 لحاف
31 قطعة
120 قطعة
57 قطعة
110 قطعة
127قطعة
169 قطعة
12 مفرش
10 مفارش
110 قطعة
170 قطعة
20 خرطوشة
28 قطعة
60قطعة
70 قطعة
80 لعبة
70 قطعة
20 قطعة
60 قطعة
50 قطعة
10 رولات
4 رولات
35 دسته
50دستة
7 رول
3 اثواب قماش
خمسة خرطوشة سجائر
50 جاكت حريمى ورجالى
10 رول اقمشة 4 دسته
420 جوارب اطفال
60 خرطوشة سجائر
12 رول
15 خرطوشة
110 علبة
45 قطعة
40 قطعة
44 قطعة
22 قطعة
3 خرطوشة
468 قطعة
38 قطعة
80 رول قماش
2 رول
6 رول اقمشة
13 رول اجنبى الصنع
100 دسته صينى الصنع
18 رولات ملابس
10دسته
90قطعة
33 قطعة
39 قطعة
42 قطعة
300 ايشارب
500 قطعة
19000 ك 0ج
607 قطعة
24 قطعة
45 قطعة
40 اروسه
5 رول اقمشة اجنبية الصنع
75 قطعة
5 قطعة
4 رول
26 قطعة
50قطعة
105 قطعة
650 جرام
65 قطعة
50 خرطوشة
4 خرطوشة
80 قطعة
100 بنطلون
500 قطعة
40 قطعة
42قطعة
1 خرطوشة
14 قطعة
80 قطعة
7 خرطوشة سجائر
230 لمبة
50 قطعة
50قطعة تليفون
14 كرتونة
4 كرتونة احذية
17 كرتونة خزف
22 لحاف
16كرتونة ادوات صحية
8كرتونة
28 كرتونة
2كرتونة
15كرتونة
115 قطعة
6448
1937قطعة
1937 قطعة
2628كجم
6.980طن
9 كرتونة
18 شفاط
صواميل حديد
3كرتونة +20 قطعة
39.480طن ق.غ سيارات
25كرتونة مصنوعات خزفية
50بنطلون
8 كرتونة كلبسات
20كرتونة اكسسوار حريمى
279كرتونة لحوم
38 اطار كاوتش
10كرتونة
4كرتونة
10كيلو
عدد5 ماكينات
41سيارة
سيارة
90 قطعة ملابس
22250كجم
1793كجم
1371كرتونة زجاج
مستندى
252شاشة
5كرتونة
320قطعة
45خرطوشة
98 قطعة
10لفات
25كجم
320كجم
5كراتين
47طرد
50قطعة
117كجم
1200 قطعة ملابس
5كجم
75جهاز
40قطعة
5كراتين
10كجم
250ق
200ق
200 توب
20لفة
30لفة
2دستة
95قطعة
70قطعة
57523طن طلمبات مياه
43732كجم
755كرتونة
10.645طن
1537طرد
11751كجم
مكبس
77426.80متر
2600قطعة
339طن
15120كجم
مختلفة
267طرد
1200كجم
189عبوة
499كرتونة
10000كجم
960طرد
15.770كجم
111قطعة
174طرد
22000كجم
473000علبة
6720كجم
145خرطوشة
2500طن
3660كجم
27824كجم
8682كجم
14000كجم
6400كجم
133كرتونة
2738كجم
the characters are in arabic here.
hope it clears my issue.
please suggest me the right query for this to get only numbers
thanks
kumar -
XPath expression for Native Schema (Opaque)
Hi people,
I have a BPEL process that dequeues a message using AQ Adapter, and we are using a Native (Opaque) schema for that, since we do not have the XSD available for this message. The XML Message generated is:
<?xml version="1.0" encoding="UTF-8" ?>
- <input_Dequeue_InputVariable>
- <part>
- <ns1:XXOD_IN_PERI_MWDProcessRequest xmlns:ns1="http://xmlns.oracle.com/XXOD_IN_PERI_MWD">
<ns1:UE>3704</ns1:UE>
<ns1:MATRICULA>00003953-0</ns1:MATRICULA>
<ns1:CODIGOVERBA>PE</ns1:CODIGOVERBA>
<ns1:TIPOVALOR>PCT</ns1:TIPOVALOR>
<ns1:DATAINICIO>2009-09-15</ns1:DATAINICIO>
<ns1:DATAFIM />
<ns1:VALOR>30,0000000</ns1:VALOR>
<ns1:ACAO>I</ns1:ACAO>
</ns1:XXOD_IN_PERI_MWDProcessRequest>
</part>
</input_Dequeue_InputVariable>
When i dequeue this, i use the following expression to get the value of tag ns1:ACAO in a copy operation:
bpws:getVariableData('input_Dequeue_InputVariable','opaque', '//ns1:ACAO')
However, this expression seems to be evaluating to NULL on the assign activity. I believe i am not using the correct Xpath expression to extract that... Do you know what is the correct XPath expression to extract this tag in this case?
I am using SOA Suite 10.1.3.5.
Best Regards
Thiago
Edited by: Thiago on Jan 28, 2010 5:08 PMHi Eric,
Unfortunately not. When the schema is Opaque, the variable in BPEL editor shows as "opaque", when i open it on the variable editor i see only the root element named "ns4:opaqueElement", and not the structure of the actual XML. I think it happens because this variable is not bound to any XSD...
Thanks and Regards
Thiago -
IDCS6 - How do I create tables with large whole numbers and small fractions?
I have a lot of engineering data, dimensions, etc, to enter into an existing IDCS6 Table. I need whole numbers to display full size, but fractions to be small size. I know I can use Open Type and select the Fractions option for each individual fraction, but that would take forever and give me a roaring headache.
How do I create a style (or whatever) that will allow me to just type in the numbers and have them automatically apply small formatting to the fraction portion of the number whenever it sees a "/"?
Along a similar line, I was trying to copy table data from a PDF document from Acrobat X Pro and paste that into an IDCS6 table, so each cell is populated by the appropriate cell data from the PDF file, but didn't have any success. That would really save me a lot of time, because I have many complete tables in PDF format. The data is not protected in the PDF, but I'm having a hard time figuring out how to bring it over to IDCS6.
On a Mac, OSX 10.8.5.
Thanks,
LouThere are a number of ways to do it, but I make fractions using Dan Rodney's excellent (and free) Proper Fraction script. After it's installed; assign it a keyboard shortcut. Then type your numerator/denominator, select it, and invoke the script. With just a couple keystrokes, you've got a perfectly formatted fraction.
As for the PDF tables, I'd try exporting the host file to RTF and copy/pasting from there. In case you're unaware, to paste values into InDesign table cells, the number of (pre-existing), cells/rows/columns in InDesign must match those copied (from) exactly, and must be pre-selected when the Paste command is executed. So...
1. Set up empty destination table in InDesign which matches the source structure.
2. Select source cells and Copy.
3. In Indesign, select exact same (x, y, qty), range of destination cells and Paste. -
Expression for the current hour
I'm trying to assign a lead based on the current time and a user's hourly shift availability - is this doable? I was thinking to use custom fields that track the user's hourly shift in a 24 hour day (e.g. shift start and end fields: for example 8am to 5pm EST, using a 24 hour clock) - maybe I should store as an integer field to better make the comparison? What is an expression to extract the current timestamp's hour so I can compare?
I think I got it tochar(timestamp,'hh24')
-
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
-
Regular Expressions for textfield syntax checking while typing?
Hi all,
my application has a textfield for entering customer numbers. The customer numbers have a certain syntax which I want to have checked while the user types.
According to our company's style guide, the textfield's background color has to be
- RED in case of an error,
- WHITE in case of correct input,
- YELLOW when the input is incomplete but the beginning is correct.
To check the syntax with Regular Expressions is easy for the WHITE and RED cases. But I'm struggling with the YELLOW case.
public static boolean checkTest(String s) {
String regExp = "(\\d{6,8},\\d{1,3},\\d{1,3},\\d{1,2})";
return Pattern.matches(regExp, s);
}The above method returns true for the following examples:
"12345678,1,2,3"
"123456,11,22,33"
"1234567,123,123,12"
I now need another method which returns true if the user entered a valid beginning, for example:
"123"
"1234567,"
"123456,123,1"
Any ideas? I would be glad to get this done...@notivago
In the meantime I also came up with a pattern to
check the YELLOW case:
String partly =
"\\d{0,8},?|\\d{6,8},\\d{0,3},?|\\d{6,8},\\d{1,3},\\d{
0,3},?|\\d{6,8},\\d{1,3},\\d{1,3},\\d{0,2}";Sounds good to me.
It seems to work. But my actual goal is to do such
color-coded syntax checking for other number types
(other patterns) as well. And it should be easy to
add or change number types.I cant figure how to do that for now.
So it would be nice to have a generic way to generate
the YELLOW-pattern from the other one. Is it
possible? Probably, but I cannot come up with any idea now.
Is there a better solution than my one
("String partly" above)? Something I can just append
to the original pattern for example?There are others, but it is hard to say what would be better or worse. -
Hello,
need to extract IDOCs numbers of a lot of IDOCs which run on a mapping error and
have been stopped in sxmb_moni. Is there a possibility to extract the IDOCs numbers as
as a list? We have XI 3.0.
Thanks
ChrisHello
@Rajesh: This is the thing I don't want to do. Look into the payload of hundreads of IDOCs is not very funny. But thanks for your answer.
@ Jaishankar and Siddhesh Pathak
IDX5 contains the needed information. Thanks for the hint. Points given. -
I have tired for this!
When I use SSIS for extract data from ssas, that means,I use mdx query.
then random error occured.
Hope some one can understand my poor English....
And the Error Info show below.
Code Snippet
Error: 0xC0202009 at Data Flow Task - For Individual User Tech Points, OLE DB Source 1 1 [31]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E05.
An OLE DB record is available. Source: "Microsoft OLE DB Provider for Analysis Services 2005" Hresult: 0x00000001 Description: "Error Code = 0x80040E05, External Code = 0x00000000:.".
Error: 0xC004701A at Data Flow Task - For Individual User Tech Points, DTS.Pipeline: component "OLE DB Source 1 1" (31) failed the pre-execute phase and returned error code 0xC0202009.I have had the same error on SQL2008 and now on SQL2012 SSIS, but have been able to eliminate / workaround.
We have a Loop Container in our Control flow that contains a data-flow task with an MDX source. The MDX query for the data-flow source is dynamically built (via an expression) on each iteration of the Loop container (however it always returns the "same shaped"
results - only the filters in the WHERE clause are different).
We've found the error to be somewhat intermittent - sometimes the package will complete successfully, other times it will fail with the 0x80040E05 error at varying iterations thru the container loop.
To alleviate the problem we setup the SQL Agent job-step for this package to re-try on failure for up to 5 retries - not an ideal workaround, but it helped to improve the success rate of the Job.
We have no idea why this error is occurring or what is causing it, however it appears to be timing-related in some way and I have only seen the issue when using a SSAS OLE-DB data source with a dynamically generated MDX query. I have managed to virtually
eliminate the error from occurring with a not ideal workaround in the SSIS package - no idea why this works/helps (hopefully Microsoft will be able to work it out and resolve the issue as it's been plaguing us since SQL2008 and is still here in SQL2012
SP1...
Workaround for MDX causing 0x80040E05 error:
Within our loop container we have added a Script task with OnSuccess precedent constraint to the data-flow task that contains the dynamically generated MDX source query. The script task simply introduces a WAIT in the processing immediately after the
data-flow task completes of about 5 seconds, before allowing SSIS to continue with the next iteration (e.g. System.Threading.Thread.Sleep(5000)).
With this delay in place we have had much more stable SSIS package executions - dont know why, but that's what we havce observed. Also note that when we migrated to SQL2012 SSIS packages the 0x80040E05 error returned, however we were able to eliminate it
once more by increasing the WAIT time to 10 seconds on this script task.
Now waiting for 10 seconds is not an ideal solution / workaround to this problem - particularly when it is contained within a Loop Container (in our case it has added nearly 30 minutes of "WAIT time" to the package execution duration), however this workaround
is better than having the package fail 80%+ of the time...
regards,
Piquet -
just bought a MacBook Air and using Numbers to make a spreadsheet for financial purposes. The sum function is working ok for whole numbers but when I try to sum a column of 2 decimal place numbers the result always comes back as 0. Can anyone help?
Hi laura,
I suspect that your 2 decimal place numbers are formatted as text. Change the format of the column to currency and see it that works.
Also You might want to update your profile to reflect your current systems!
quinn -
Errors trying to apply a Boolean expression for conditional text
I have been trying to create some Boolean expressions to filter conditional text, with mixed results. The Boolean expression is three conditions separated by ORs followed by four conditions preceded by AND NOTs. When I apply the expression, FrameMaker exhibits and error and has to quit. The numbers in the error message are:
9004, 4908044, 6134440, 5459515
The hidden log file appears to be nothing more than a stack dump.
Do the numbers listed above indicate anything?
Are there any known limitations on how long a Boolean expression can or should be? One expression with one fewer OR worked.
Does there need to be a space between an AND and a NOT? The builder does add one, so I assume it is not necessary.
Does anyone have some general rules of thumb when working with Boolean expressions for conditional text?
Thanks,
VanVan,
The error values are meaningless to users. However, please do send the logfiles to the [email protected] address.
As far as conditionals go, the general rules are that conditon names must be quoted and that if your ar using the NOT, it must run together with the AND or OR, e.g. ANDNOT ORNOT.
There's an articel in the Developer Connection on using the boolean operators at http://www.adobe.com/devnet/framemaker/articles/fm8_single_sourcing.html
Perhaps if you posted the condition that caused the crash, someone might be able to spot an error.
Maybe you are looking for
-
Mail application keeps crashing
Every time I go to open Mail it crashes. Please help! If this helps, here is the error report: Process: Mail [601] Path: /Applications/Mail.app/Contents/MacOS/Mail Identifier: com.apple.mail Version: 3.1 (914) Build Info: Mail-9140000~1 Code Type: X8
-
On Win7 computer, how can I see all files on iPod touch?
I have an iPod touch 4.3.5 (8L1), model MC540C. When it's plugged into my Windows 7 computer, I want to be able to see all the files (not just the photos). What must i do to see all the files? My ultimate purpose is to copy one file: the voice record
-
Camera raw is selective in operation.
Camera raw 2.4 only opens when opening an image using the Photoshop CS file browser. In the past i have been able to open the image from whatever folder location outside of the browser and Photoshop CS would open then opening the image in camera raw.
-
Conversion anomalies with Acrobat Professional 8 and Word 2007
We recently upgraded to Word 2007 from 2003. I updated a Word 2003 document, as I do every year, with minimal changes. When I converted it to pdf with Acrobat 8.1.5, two unexpected things happened. One, none of the hyperlinks converted--they've alway
-
Songs transferred into my ipod go out of sync.
Hi everyone, my 1st post hope you can help me, when i put full albums from itunes7 into my ipod nano, sometimes in the nano 1 full album, will be shown 2 or 3 times in the artist category i.e elbow album leaders of the free world, when I go into arti