Viewing profile — unlinkr
unlinkr
HN member- Joined
- Mon, Sep 02, 2019, 4:29 PM UTC
- HN karma
- 17
- Public activity
- 30 items
- HN profile
- View on Hacker News ↗
About unlinkr
No profile information was provided.
Recent public activity
-
comment
Comment #20927928
So it seems we agree that for the question the OP is actually asking a regex is the appropriate tool. Great if you can recommend a tool which can solve the task easier. But saying …
-
comment
Comment #20925806
I'm not familiar with antlr or javacc, but don't they use regular expressions for lexing?
-
comment
Comment #20918254
That is just a comment and can be easily scanned by a regex. The CDATA syntax does not have any particular meaning inside an XML comment if that is what you are suggesting. And in …
-
comment
Comment #20917916
Sure. But that would be true for any parsing technique. No parser known to man would be able to produce a valid parse if you start it in the middle of a quoted string!
-
comment
Comment #20917813
The job (the question asked) is about recognizing start and end tags in XHTML. These are lexical tokens and therefore regular expressions are a perfectly fine tool for this. Indeed…
-
comment
Comment #20917259
This is what I really hate about the Zalgo answer. It is instilling people some vague sense that regular expressions are somehow bad, wrong and dangerous. But without any real argu…
-
comment
Comment #20916856
You have to distinguish between the different levels of parsing. Regexes are appropriate for tokenization, which is the task of recognizing lexical units like start tags, end tags,…
- comment
-
comment
Comment #20916371
That pattern would indeed match a quoted string. I don't see how it would matter if the quoted string contains something like "<input". It can contain anything except a quote chara…
-
comment
Comment #20916334
No, you don't need more than a regular expression. If you want to extract elements , i.e. match start tags to the corresponding end tags, then you need a stack-based parser. But ju…
-
comment
Comment #20916309
Why would a hand-written lexer have fewer mistakes than a regular expression using an off-the-shelf regex engine? They would need to encode the same lexical grammar, so at that lev…
-
comment
Comment #20916061
I actually meant (? in order to create a named capture.
-
comment
Comment #20916032
So how would you tokenize without the use of regular expressions? What more appropriate technique would you use instead? The example you provide in not XHTML so not really relevant…
-
comment
Comment #20916004
The problem is it is funny and wrong . Apparently it have given a lot of people really confused ideas about what is possible and what is not possible with regular expressions. If i…
-
comment
Comment #20915984
It was supposed to be (? \w+ ) in order to create a named capture. The was apparently lost in editing. Thanks for the heads-up.
-
comment
Comment #20915656
The problem with the answer is it is wrong. The question is about identifying start-tags in XHTML. This is a question of tokenization and can be solved with a regular expression. I…
-
comment
Comment #20915540
Yes you can tokenize this with a regular expression and extract the valid start and end tags. If comments in XHTML could nest you would have a problem. But this is not the case.
-
comment
Comment #20912662
> Maybe you can detect tags with regex, but maybe you shouldn't... So what do you think would be a more appropriate choice for writing a tokenizer?
-
comment
Comment #20911932
I think there are a lot of knee-jerk answer because people see "XHTML" and "regex" in the same sentence and immediately think "not possible". But the actual question is clearly not…
-
comment
Comment #20911833
You don't need to keep track of state to match tokens like XHTML start or end tags.
-
comment
Comment #20911821
That is a valid XHTML tag (if I remember correctly) and can be matched perfectly fine by a regex.
-
comment
Comment #20911376
An element requires a start and end tag, or a self-closing start tag.
-
comment
Comment #20911365
That is not XHTML.
-
comment
Comment #20910794
How do you think an XHTML parser is written? In particular, how does an XHTML parser identify tokens like start and end tags?
-
comment
Comment #20910598
It only works in practice, not in theory.