|
I need to get the values from below following html snippet. So far I came up with this regex which helps me trim it down to the values I needed, but to automate this I need to join 2 regex statements to get the result "18" which is where I am stuck at. Or Please suggest a better method for me get the values.
I am using WebHarvey scraping tool. The program is based on .net but it doesn't support inserting .net code so I need only regex command.
First Regex Statement
(?s)(?<=attribute bathroom).+?(?=\/span)
Result:
" title="Bathrooms" style=" ">
<span class="value" style=" ">18<
Second Regex Statement
(?s)(?<=<span class="value" style=" ">).+?(?=<)
Result: 18
HTML Snippet
<ul class="iconContainer" style=" ">
<li class="attribute propertyId">
xxx1
</li>
<li class="attribute propertyType">
Factory
</li>
<li class="attribute bathroom" title="Bathrooms" style=" ">
18
</li>
<li class="attribute carspace" title="Car Spaces" style=" ">
18
</li>
<li class="attribute landArea">
<span title="Land Area">
5,010<span class="unit">mclass="superscript"></span>
</span>
<span>|</span>
<span title="Floor Area">
9,270<span class="unit">m^__b class="superscript">2</span>
</span>
</li>
</ul>
|
|
|
|
|
Please do not repost the same question. You can easily edit your own questions if you need to add more details.
|
|
|
|
|
Don't try to use Regex to parse an HTML document. You'll end up with an extremely fragile solution, where even the slightest change to the source document will cause it to break.
Use a proper HTML parsing library instead - for example, AngleSharp[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In my question I have mentioned "
I am using WebHarvey scraping tool. The program is based on .net but it doesn't support inserting .net code so I need only regex command. "
I cannot use any solution except using regex in this tool. When 2 of my regex statements are bringing the result I wanted then I am pretty sure using regex can get the solution needed but due to lack of knowledge I am stuck here.
Parsing HTML with regex is not best practice but I am willing to take the risk. Suggest a solution please.
|
|
|
|
|
He was saying instead of using WebHarvery, use AngleSharp instead.
|
|
|
|
|
I'd suggest getting a better scraping tool, or writing your own.
Given the sample input, this regex should match:
(?<=class="attribute bathroom"[^>]*>\s*<span[^>]*>)[^<]+ Demo[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi, I'd lke to subsitute the string Alfa("Beta") to Alfa(Gamma("Beta")) using regular expressions in Visual Studio using regexp.
The first part is simple, the search string will be Alfa\("(.*)"\)
But how to specify the replacement string? I used Alfa\(Gamma\("(.*)"\)\) , but the result was Alfa(Gamma("(.*)")) and not the requested Alfa(Gamma("Beta"))
Thank you for your advice in advance
|
|
|
|
|
|
Thank you!
|
|
|
|
|
Hi Richard,
I used your advice and it worked perfectly. The search string was alfa\("(.*)"\) and the regexp substitute string was alfa(gamma("$1")) Thus I obtained the wished result string alfa(gamma("beta"))
But one more question: I encountered an input string alfa("beta","delta") and the wished result string should be alfa(gamma("beta"),"delta"), but I obtained alfa(gamma("beta","delta"))
How to change regexp to achieve this?
Thank you, best regards,
Michael
|
|
|
|
|
Maybe so?
alfa\("([^"]*)"(.*)
replace with
alfa(gamma("$1")$2
|
|
|
|
|
|
Hi
I have a line in my csv file as below
""|*"I have delimiter |* and an escaped \" quote in me"|*100|*200|*300|*"am a string"|*""
I have to interpret " quote as text-qualifier and |* as delimiter. I have to ignore escaped quote \" and consider it part of the string. 100, 200, 300 are integer data fields, so, they are not surrounded by text-qualifier.
The expected result is an array of strings.
a[0] = "" which is a Null string
a[1] = "I have delimiter |* and an escaped \" quote in me"
a[2] = "100"
a[3] = "200"
a[4] = "300"
a[5] = "am a string"
a[6] = "" which is a Null string
Code is as below, it looks like \" is not getting escaped properly, could you please let me know how to fix this, thanks.
The RegularExpression code is as in here: Split Function that Supports Text Qualifiers[^]
using System.Text.RegularExpressions;
public string[] Split(string expression, string delimiter,
string qualifier, bool ignoreCase)
{
string _Statement = String.Format
("{0}(?=(?:[^{1}]*{1}[^{1}]*{1})*(?![^{1}]*{1}))",
Regex.Escape(delimiter), Regex.Escape(qualifier));
RegexOptions _Options = RegexOptions.Compiled | RegexOptions.Multiline;
if (ignoreCase) _Options = _Options | RegexOptions.IgnoreCase;
Regex _Expression = New Regex(_Statement, _Options);
return _Expression.Split(expression);
}
|
|
|
|
|
Your function works fine for me if you pass in the correct values.
const string input = "\"\"|*\"I have delimiter |* and an escaped \\\" quote in me\"|*100|*200|*300|*\"am a string\"|*\"\"";
string[] result = Split(input, "|*", @"\""", false); Split | C# Online Compiler | .NET Fiddle[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
i got an 9 million row excel file and i need to join it with another excel file base on numeric values.
Issue :
I suppose to have only unique numbers in column A, but unfortunately i got some characters in some columns.
When i try to join the two excel i get an error : dataFormat.Error: We couldnt convert number.
How can i :
1. delete rows where i got alphanumeric values in columns
2. filter out alphanumeric - powerbi, excel or any other software
Thank you
|
|
|
|
|
I can find plenty of examples of how to find a number in a string, but now how to find a number preceded by a specific string.
Like...
[2020-07-24_184102][ACF11B2Y90][CCT]_Cycle0001.csv
How can I say "give me the number that follows the text 'Cycle'?"
|
|
|
|
|
|
Thanks Richard. I finally ended up working out the following:
(?<=Cycle)\d{4}
This returns the '0001' like I want. I actually came close to working this out before posting, but failed to notice that I had a space before the \d. Duh.
|
|
|
|
|
Hello.
I am an editor at english wikipedia. I am adding template of wikiproject banners on the talkpages of articles which come under the scope of wikiproject. Basically, I am adding
{{WikiProject Espionage |importance=Mid |class=Start}}
to the talkpages of the articles. For that I use a tool called as auto wiki browser (AWB). Wikipedia:AutoWikiBrowser - Wikipedia[^]
Currently, I am using following module:
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
Regex header = new Regex(@"\{\{{WikiProject Espionage|{{WikiProject Espionage |{{WP Espionage|{{WikiProject Intelligence |", RegexOptions.IgnoreCase);
Summary = "Added banner for [[WP:WikiProject Espionage|WikiProject Espionage]]";
Skip = (header.Match(ArticleText).Success || !Namespace.IsTalk(ArticleTitle));
if (!Skip)
ArticleText = "{{WikiProject Espionage|class=|importance=|listas=}} \r" + ArticleText;
return ArticleText;
}
In the module, "WP Espionage", and "WikiProject Intelligence" are shortcuts/redirects to WikiProject Espionage. The module tells AWB to add the template to the article, and skip if any of these templates are already present. But the problem is, there is another wikiproject by the "Wikiproject Intelligence Agency". So my module is skipping the pages if there is Wikiproject Intelligence Agency already present on the page.
So my question is: is there a way to tell AWB to skip only if {{WikiProject Espionage, {{WP Espionage, and {{WikiProject Intelligence and to avoid the presence of {{Wikiproject Intelligence Agency ?
Any help will be appreciated a lot. Regards, —usernamekiran.
|
|
|
|
|
if ( ArticleText.Contains( "Wikiproject Intelligence Agency" ) ){
} else {
}
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I need to find 5 sequence of alphabets has exists in a given string using regular expression.
Sequence which should check in any of the form like ABCDE, BCDEF, DEFGH, EFGHI,......,PQRST,...,VWZYZ.
Eg.
1) ABCDECODEPROJECT - Match (because "ABCDE" has exists in the string)
2) TESTSTRING - Not Match (because No 5 sequence of alphabets)
3) SAMPLEQRSTUEND - Match (because "QRSTU" has exists in the string)
4) WEBSITELMNOPEND - Match (because "LMNOP" has exists in the string)
5) QUESTIONANSWER - Not Match (because No 5 sequence of alphabets)
Can you help me on build regular expression to check all possible combination in alphabets?
|
|
|
|
|
|
This doesn't look like a suitable case for regular expressions. You'd have to build a regex pattern containing every possible sequence to test for, because regex doesn't have a construct for comparing the difference between two characters within a match.
It would probably be easier to implement this using a loop. Check each five-character substring from the input to see if it's contained within a string containing the letters in sequence, remembering to account for case and accents if required.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi there,
Here is part of a Python Code I have :-
#convert df['Durn'] column to datetime foramt
df['Durn']= pd.to_datetime(df['Durn'],format='%H:%M:%S').apply(pd.Timestamp)
#print("changing datatype of column Durn----->",df['Durn'].dtype)
#print("=======")
#compare minutes with extracting minutes from datetime64 column
comparelist=[5,10,15,20,]
df['Dakota And Fighters In The Same Display Slot'] = ((df['DISPLAY/'] == 'DISPLAY') & (df['Durn'].dt.minute.isin(comparelist))).map({True:'YES', False:'NO'})
#print(df)
#print("applied... the condition to compare minutes for Durn column")
#print("=======")<pre><pre>
The Rows that, I would like showing, and that have in the 'Dakota And Fighters In The Same Display Slot' Column, saying 'NO', arn't showing in the output. For a given Venue, in the 'Venue' Column, the rows not showing, both Minute Values in the 'Durn' Column, differ i.e. are normally 5 and 10. Only the Rows with matching values, in the 'Durn' Column i.e. 5 and 5, 10 and 10, 15 and 15, 20 and 20. etc are displaying in the Output I get. Those are the ones that say 'Yes', in the Column I have mentioned already.
What Regular Expression with using Maths, could I add to my Code, so that those Rows, I want showing show ?
Any help would be appreciated
Regards
Eddie Winch
|
|
|
|
|
From a tab-based tree-like file, I'd like to get a flat-file DB (I think I'll make a program out of it and probably using ECMAScript/JavaScript, but whatever I end up doing I need a DB to start with). The file have different 1st-level block items, that is starting right after \n and ending just before either "\n\w" or EOF (end of file); I'm only interested in a certain kind: starting with "\nsystem\s", which I'll refer to as "system". A good portion of systems have a 2nd-level (non-block) item, that is starting right after \n\t and ending just before either "\n" or EOF (end of file); I'm only interested in those starting with "\n\tlink\s", which I'll refer to as "link"; any of those cases have > 1 link. I'm thinking the links can be in a CSV. All systems have a single 2nd-level "pos", which has 2 digits, that can be negative.
To summarize: Not all 1st-level items are systems but I'm only interested those. Some systems have no link, a decent portion have just 1, and a large portion have > 1, whichever of those cases I need links to be listed. A good portion of names, be it system or link are double-quoted which I don't want (the quotes).
The input file is https://github.com/endless-sky/endless-sky/blob/master/data/map.txt and the following is its current version 1st 2 systems trailed by an example of a system without a link and after is the output I'm looking to have from that.
I'd prefer to run the regex in Notepad++, but worse case I have Cygwin so I could use some *nix tools although please note often Cygwin version is old (so if someone want me to use the latest *nix tool, there's a decent chance I won't be able to in Cygwin).
Thank you kindly for your help
Sample input
```text
# Copyright (c) 2014 by Cookie Monster
system "1 Axis"
pos -1274.63 267.214
government Coalition
habitable 745.92
belt 1112
link "Sol Kimek"
link "4 Winter Rising"
link "4 Spring Rising"
link "3 Axis"
asteroids "small rock" 8 3.3166
asteroids "medium rock" 11 3.4454
asteroids "large rock" 1 3.1556
asteroids "small metal" 1 3.381
asteroids "medium metal" 149 4.347
asteroids "large metal" 11 3.9606
minables lead 11 6.87213
minables silicon 35 6.68659
minables tungsten 2 5.45307
trade Clothing 251
trade Electronics 831
trade Equipment 469
trade Food 231
trade "Heavy Metals" 1241
trade Industrial 767
trade "Luxury Goods" 1135
trade Medical 777
trade Metal 520
trade Plastic 384
fleet "Small Arach" 700
fleet "Large Arach" 1500
fleet "Small Kimek" 300
fleet "Large Kimek" 400
fleet "Small Saryd" 900
fleet "Large Saryd" 1800
fleet Heliarch 450
object
sprite star/k5
distance 49.335
period 18.0618
offset 180
object
sprite star/m0
distance 65.665
period 18.0618
object
sprite planet/rock12-b
distance 298.105
period 75.382
object
sprite planet/cloud4-b
distance 728.595
period 288.034
object "Celestial Third"
sprite planet/ice4
distance 951.355
period 429.762
object
sprite planet/gas9-b
distance 1811.79
period 1129.48
object
sprite planet/lava0
distance 229
period 12.994
object
sprite planet/dust1
distance 394
period 29.3248
object
sprite planet/dust5
distance 565
period 50.3574
object
sprite planet/ice8
distance 684
period 67.0771
system "10 Pole"
pos -1356.63 19.2137
government Coalition
habitable 486.68
belt 1765
link "16 Autumn Rising"
asteroids "small rock" 30 10.7996
asteroids "medium rock" 42 8.4448
asteroids "large rock" 2 8.12
asteroids "medium metal" 9 11.368
asteroids "large metal" 2 4.7096
minables neodymium 9 17.5036
minables silicon 17 18.2422
trade Clothing 335
trade Electronics 832
trade Equipment 444
trade Food 122
trade "Heavy Metals" 1228
trade Industrial 806
trade "Luxury Goods" 1009
trade Medical 710
trade Metal 300
trade Plastic 342
fleet "Small Arach" 1800
fleet "Large Arach" 8000
fleet "Small Kimek" 600
fleet "Large Kimek" 1600
fleet "Small Saryd" 1200
fleet "Large Saryd" 5000
fleet Heliarch 700
object
sprite star/k0
period 10
object
sprite planet/ice2
distance 158.89
period 36.3148
object "Second Rose"
sprite planet/cloud4
distance 483.25
period 192.618
object
sprite planet/rock17
distance 152
period 17.6262
object
sprite planet/lava2-b
distance 1069.5
period 634.175
object
sprite planet/gas16
distance 1649.46
period 1214.65
object
sprite planet/gas8-b
distance 2382.55
period 2108.63
object
sprite planet/rhea
distance 230
period 18.5682
object
sprite planet/dust3
distance 335
period 32.6395
object
sprite planet/ice0
distance 490
period 57.7392
system "yummy stew"
pos -666.66 333.333
government potato
habitable 999.99
belt 4444
asteroids "small rock" 8 3.3166
asteroids "medium rock" 11 3.4454
asteroids "large rock" 1 3.1556
asteroids "small metal" 1 3.381
asteroids "medium metal" 149 4.347
asteroids "large metal" 11 3.9606
minables lead 11 6.87213
minables silicon 35 6.68659
minables tungsten 2 5.45307
```
Output from sample
```text
System X Y links
1 Axis -1274.63 267.214 Sol Kimek, 4 Winter Rising, 4 Spring Rising, 3 Axis
10 Pole -1356.63 19.2137 16 Autumn Rising
yummy stew -666.66 333.333
```
Je vous salue du Québec !
|
|
|
|
|