Click here to Skip to main content
14,668,357 members
Home » Discussions » Regular Expressions
   

Regular Expressions

 
QuestionRegEx: Get Values from HTML Attribute Tags Pin
Member 1046475230-Sep-20 19:47
MemberMember 1046475230-Sep-20 19:47 
AnswerRe: RegEx: Get Values from HTML Attribute Tags Pin
Richard MacCutchan30-Sep-20 21:26
mveRichard MacCutchan30-Sep-20 21:26 
AnswerRe: RegEx: Get Values from HTML Attribute Tags Pin
Richard Deeming30-Sep-20 22:14
mveRichard Deeming30-Sep-20 22:14 
GeneralRe: RegEx: Get Values from HTML Attribute Tags Pin
Member 104647521-Oct-20 3:58
MemberMember 104647521-Oct-20 3:58 
GeneralRe: RegEx: Get Values from HTML Attribute Tags Pin
Dave Kreskowiak1-Oct-20 4:41
mveDave Kreskowiak1-Oct-20 4:41 
GeneralRe: RegEx: Get Values from HTML Attribute Tags Pin
Richard Deeming1-Oct-20 4:41
mveRichard Deeming1-Oct-20 4:41 
QuestionString Replacement Pin
Michael Eckstein19-Sep-20 20:27
MemberMichael Eckstein19-Sep-20 20:27 
AnswerRe: String Replacement Pin
Richard MacCutchan19-Sep-20 21:11
mveRichard MacCutchan19-Sep-20 21:11 
GeneralRe: String Replacement Pin
Michael Eckstein19-Sep-20 22:28
MemberMichael Eckstein19-Sep-20 22:28 
GeneralRe: String Replacement Pin
Michael Eckstein20-Sep-20 0:19
MemberMichael Eckstein20-Sep-20 0:19 
GeneralRe: String Replacement Pin
Michael Eckstein20-Sep-20 1:01
MemberMichael Eckstein20-Sep-20 1:01 
GeneralRe: String Replacement Pin
Richard MacCutchan20-Sep-20 1:32
mveRichard MacCutchan20-Sep-20 1:32 
QuestionRegEx Split Pin
Member 148774747-Sep-20 7:56
MemberMember 148774747-Sep-20 7:56 
AnswerRe: RegEx Split Pin
Richard Deeming7-Sep-20 22:43
mveRichard Deeming7-Sep-20 22:43 
Question9 million Rows in Excel Pin
IzaacSpyro30-Aug-20 22:20
MemberIzaacSpyro30-Aug-20 22:20 
QuestionFinding a specific number in a string. Pin
Member 1086910714-Aug-20 11:36
MemberMember 1086910714-Aug-20 11:36 
AnswerRe: Finding a specific number in a string. Pin
Richard MacCutchan14-Aug-20 21:40
mveRichard MacCutchan14-Aug-20 21:40 
GeneralRe: Finding a specific number in a string. Pin
Member 1086910715-Aug-20 1:17
MemberMember 1086910715-Aug-20 1:17 
QuestionHow to skip a particular term in regex find and replace? Pin
usernamekiran11-Aug-20 4:34
Memberusernamekiran11-Aug-20 4:34 
AnswerRe: How to skip a particular term in regex find and replace? Pin
Gerry Schmitz11-Aug-20 6:39
mveGerry Schmitz11-Aug-20 6:39 
QuestionFind Sequence of alphabets in the string Pin
arisaravanan11-Apr-20 1:32
Memberarisaravanan11-Apr-20 1:32 
AnswerRe: Find Sequence of alphabets in the string Pin
Richard MacCutchan11-Apr-20 4:21
mveRichard MacCutchan11-Apr-20 4:21 
AnswerRe: Find Sequence of alphabets in the string Pin
Richard Deeming14-Apr-20 0:30
mveRichard Deeming14-Apr-20 0:30 
QuestionUsing A Regular Expression To Show Rows In Pandas (Python) Pin
Eddie Winch2-Feb-20 9:05
MemberEddie Winch2-Feb-20 9:05 
QuestionTSV out of a tab-based tree-like file Pin
DynV9-Nov-19 19:43
MemberDynV9-Nov-19 19:43 
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 !

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.