Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-28 Thread Caleb Herbert
I don't remember what it did, but I tried -n, and it gave a worse
result.



Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-28 Thread Adonay Felipe Nogueira
Well, in this case, the suggestions given by Magic Banana work well
together with mine. ;)

The extra line that you said gets inserted is because you forgot `-n',
if you absolutely don't want `-n', then remove the `p' flag from the `s'
command.

2017-11-27T18:18:36-0600 Caleb Herbert wrote:
> Your suggestion does not add to the lines.  It deletes them entirely.
>
> 
> cal@leela:~$ sed 's/^x .*\(.\)$/CHARIZARD/gp' "file.txt"
> c ^x a1
> y b2
> z c3
> b x d4
> y e5
> z f6
> CHARIZARD
> CHARIZARD
> a ^x 
> y 
> z 
> e ^x
> x 
> d qwerty ^x azerty aBc
> 
>
> Also, it matches incorrectly.
>
>   * An extra CHARIZARD line was inserted
>   * "x " at the beginning of the penultimate line was NOT matched
>
> My intended result is to ADD text to the end of any lines that start
> with "x ".
>
> 
> c ^x a1
> y b2
> z c3
> b x d4
> y e5
> z f6
> x abC W-CHARIZARD
> a ^x 
> y 
> z 
> e ^x
> x CHARIZARD
> d qwerty ^x azerty aBc
> 


Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Caleb Herbert

> If you instead want "^" to be considered as special in "^x ", this:
> 
> --8<---cut here---start->8---
> sed -n 's/^x .*\(.\)$/\1/gp' "file.txt"
> --8<---cut here---end--->8---

Your suggestion does not add to the lines.  It deletes them entirely.


cal@leela:~$ sed 's/^x .*\(.\)$/CHARIZARD/gp' "file.txt"
c ^x a1
y b2
z c3
b x d4
y e5
z f6
CHARIZARD
CHARIZARD
a ^x 
y 
z 
e ^x
x 
d qwerty ^x azerty aBc


Also, it matches incorrectly.

  * An extra CHARIZARD line was inserted
  * "x " at the beginning of the penultimate line was NOT matched

My intended result is to ADD text to the end of any lines that start
with "x ".


c ^x a1
y b2
z c3
b x d4
y e5
z f6
x abC W-CHARIZARD
a ^x 
y 
z 
e ^x
x CHARIZARD
d qwerty ^x azerty aBc





Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Adonay Felipe Nogueira
In the last paragraph, by "line terminator", I meant either:

- line feed only (LF, 0x0A, "\n"). Default for Unix-compliant operating
  systems such as GNU;

- carriage return only (CR, 0x0D, "\r"). Default for Mac;

- carriage return and line feed (CRLF, 0x0D, "\r\n"). Default for
  Windows.

Most commands assume that you are dealing with LF only, so the special
"$" in regular expressions already mean only "\n". There are other tools
such as `tr' which can do translations (replacements from one terminator
to other) and also `awk' for which by modifying some Awk variables you
can change how it considers input records as terminated (noting that
"records" for Awk can be considered as lines by default).

2017-11-27T21:34:33-0200 Adonay Felipe Nogueira wrote:
> I assume that by "the end" of the line you want to actually capture the
> last character, which ever it is.
>
> Suppose you have a text file like this (the underlines are *also*
> spaces, please correct them):
>
> --8<---cut here---start->8---
> c ^x a1
> y b2
> z c3
> b x d4
> y e5
> z f6
> x abC W-
> a ^x_
> y_
> z_
> e ^x
> x_
> d qwerty ^x azerty aBc
> --8<---cut here---end--->8---
>
>
> Then, assuming you want to match a literal "^x " and are using Basic
> Regular Expressions in GNU `sed', a command such as this:
>
> --8<---cut here---start->8---
> sed -n 's/^.*\^x .*\(.\)$/\1/gp' "file.txt"
> --8<---cut here---end--->8---
>
>
> Would print:
>
> --8<---cut here---start->8---
> 1
> c
> --8<---cut here---end--->8---
>
>
> If you instead want "^" to be considered as special in "^x ", this:
>
> --8<---cut here---start->8---
> sed -n 's/^x .*\(.\)$/\1/gp' "file.txt"
> --8<---cut here---end--->8---
>
>
> Would display this:
>
> --8<---cut here---start->8---
> -
> --8<---cut here---end--->8---
>
>
> The `-n' option in `sed' tells it to print only when asked to, the
> `s/regex/subst/flags' looks for a match of regular expression and
> replaces it, the "g" flag makes it replace all matches, and "p" prints
> the line if a match was found.
>
> Notice however that the captures made so far (of the last character)
> don't overlap with the controlling match ("^x "), that is, so far a
> string such as "x " wouldn't have the space captured. As far as my
> limited knowledge goes, in cases where you have to do a second match
> based on the existance of another match, it's more readable to use *two*
> regular expressions (there are some regular expression standards that
> allow this nesting at the expense of human readability, but I'm still
> not that good on these ones).
>
> The commands bellow use *two* regular expressions, for literal "^x " and
> for the special "^" in "^x ", respectively:
>
> --8<---cut here---start->8---
> sed -n '/\^x / { s/^.*\(.\)$/\1/gp }' "file.txt"
> sed -n '/^x / { s/^.*\(.\)$/\1/gp }' "file.txt"
> --8<---cut here---end--->8---
>
> Unless an address is given, `sed' applies commands to all lines. The
> /regex/ is an address type that selects lines matching a regular
> expression. After the address comes a command, the "{" and "}" are there
> for readability (but are very important if you would want to apply more
> commands to the same address).
>
> Yet again I must remind you that some programming languages have
> different regular expression standards, and so far I don't know which
> one you want.
>
> Finally, if you want to capture the line feed literally, then this can
> be more tricky. Personally, I would test how the file's first line ends
> and apply the same for the future lines I want to write.
>
> I hope this helps. ;)


Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Adonay Felipe Nogueira
I assume that by "the end" of the line you want to actually capture the
last character, which ever it is.

Suppose you have a text file like this (the underlines are *also*
spaces, please correct them):

--8<---cut here---start->8---
c ^x a1
y b2
z c3
b x d4
y e5
z f6
x abC W-
a ^x_
y_
z_
e ^x
x_
d qwerty ^x azerty aBc
--8<---cut here---end--->8---

Then, assuming you want to match a literal "^x " and are using Basic
Regular Expressions in GNU `sed', a command such as this:

--8<---cut here---start->8---
sed -n 's/^.*\^x .*\(.\)$/\1/gp' "file.txt"
--8<---cut here---end--->8---

Would print:

--8<---cut here---start->8---
1
c
--8<---cut here---end--->8---

If you instead want "^" to be considered as special in "^x ", this:

--8<---cut here---start->8---
sed -n 's/^x .*\(.\)$/\1/gp' "file.txt"
--8<---cut here---end--->8---

Would display this:

--8<---cut here---start->8---
-
--8<---cut here---end--->8---

The `-n' option in `sed' tells it to print only when asked to, the
`s/regex/subst/flags' looks for a match of regular expression and
replaces it, the "g" flag makes it replace all matches, and "p" prints
the line if a match was found.

Notice however that the captures made so far (of the last character)
don't overlap with the controlling match ("^x "), that is, so far a
string such as "x " wouldn't have the space captured. As far as my
limited knowledge goes, in cases where you have to do a second match
based on the existance of another match, it's more readable to use *two*
regular expressions (there are some regular expression standards that
allow this nesting at the expense of human readability, but I'm still
not that good on these ones).

The commands bellow use *two* regular expressions, for literal "^x " and
for the special "^" in "^x ", respectively:

--8<---cut here---start->8---
sed -n '/\^x / { s/^.*\(.\)$/\1/gp }' "file.txt"
sed -n '/^x / { s/^.*\(.\)$/\1/gp }' "file.txt"
--8<---cut here---end--->8---

Unless an address is given, `sed' applies commands to all lines. The
/regex/ is an address type that selects lines matching a regular
expression. After the address comes a command, the "{" and "}" are there
for readability (but are very important if you would want to apply more
commands to the same address).

Yet again I must remind you that some programming languages have
different regular expression standards, and so far I don't know which
one you want.

Finally, if you want to capture the line feed literally, then this can
be more tricky. Personally, I would test how the file's first line ends
and apply the same for the future lines I want to write.

I hope this helps. ;)

2017-11-27T15:01:09-0600 Caleb Herbert wrote:
> The '$' (end) of any line that matches '^x '.
>
>


Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Caleb Herbert
The '$' (end) of any line that matches '^x '.



Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Adonay Felipe Nogueira
Unfortunatelly no, but you can test with various dummy files/texts.

I wonder however, what exactly you want the regular expression to match,
or not to match, and which programming language is it?

2017-11-27T11:56:02-0600 Caleb Herbert wrote:
> Does it have a regex key on the side or elsewhere?
>
>


Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Caleb Herbert
Does it have a regex key on the side or elsewhere?



Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Adonay Felipe Nogueira
That was exactly my suggestion, with the advantage that you don't need
internet. ;)

2017-11-27T10:59:53-0600 Caleb Herbert wrote:
> I'm using Regexr because I want something like Daring Fireball's
> Markdown Web Dingus, but for regular expressions.
>
> https://daringfireball.net/projects/markdown/dingus
>
>


Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Caleb Herbert
I'm using Regexr because I want something like Daring Fireball's
Markdown Web Dingus, but for regular expressions.

https://daringfireball.net/projects/markdown/dingus



Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Adonay Felipe Nogueira
I don't understand how interactive it's supposed to be?

Do you mean that it should ask you everytime "do you want to match
file?".

I don't which RegEx engine you want to use, nor the programming
language, but at least in GNU `find', one can use something like:

find "." -regex '.*\.png$' -print

... this will search recursively from the current directory (!) and
print the relative path to each matched file that has .png file
extension (although this doesn't guarantee that the MIME type will be
that of .png file). This provides some "interactive result" because it
does nothing besides printing the matches.

Note that GNU `find' uses Emacs regular expressions by default (unless
you use `-regextype' before), which as far as I know is similar to Basic
Regular Expressions but with more features.

Finally, notice that your `-regex' must deal with the full relative path,
that is, simply using "\.png$" would return nothing (because it fails to
consider "." path, and also the subdirectories).

You could elaborate a little more and say that you only want things
inside two directory/path levels, like so:

find "." -regex '\([^/]+/\)\([^/]+/\)[^/]+\.png$' -print

But this is probably not efficient, it would be best to use:

find "." -mindepth 2 -maxdepth 2 -name '*.png' -print

Note that in the last command example `-name' uses Pathname Expansion
(see `info bash' for explanation), not regular expressions.

2017-11-27T08:43:50-0600 Caleb Herbert wrote:
> If I were going that route, I'd be using regex-builder in Emacs, but
> sometimes even it isn't interactive enough.
>
>

-- 
- https://libreplanet.org/wiki/User:Adfeno
- Palestrante e consultor sobre /software/ livre (não confundir com
  gratis).
- "WhatsApp"? Ele não é livre. Por favor, veja formas de se comunicar
  instantaneamente comigo no endereço abaixo.
- Contato: https://libreplanet.org/wiki/User:Adfeno#vCard
- Arquivos comuns aceitos (apenas sem DRM): Corel Draw, Microsoft
  Office, MP3, MP4, WMA, WMV.
- Arquivos comuns aceitos e enviados: CSV, GNU Dia, GNU Emacs Org, GNU
  GIMP, Inkscape SVG, JPG, LibreOffice (padrão ODF), OGG, OPUS, PDF
  (apenas sem DRM), PNG, TXT, WEBM.


Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Caleb Herbert
If I were going that route, I'd be using regex-builder in Emacs, but
sometimes even it isn't interactive enough.



Re: [Trisquel-users] Abrowser won't run Regexr

2017-11-27 Thread Adonay Felipe Nogueira
1. Make a test folder/directory with various dummy files that would be
   similar to the RegEx (if you are making directory/path expansion
   tests). Or a test file with contents inside (if you are testing for
   file's contents).

2. Make the RegEx software attempt the wanted RegEx against that
   directory or file.

See the results.

Done, no need to run any "RegExr". ;)

Alternatively, go to the support channels of the programming language
you are writting on and ask there for a revision on the matter, or you
can also ask us here. ;)

2017-11-24T14:48:22-0600 Caleb Herbert wrote:
> I'm having issues running Regexr in Abrowser.
>
> http://bluehome.net/csh/screenshot/2017/11/24/regexr
>
> What could be going wrong?
>
> Regexr is a free software web app for interactively exploring regular
> expressions.

-- 
- https://libreplanet.org/wiki/User:Adfeno
- Palestrante e consultor sobre /software/ livre (não confundir com
  gratis).
- "WhatsApp"? Ele não é livre. Por favor, veja formas de se comunicar
  instantaneamente comigo no endereço abaixo.
- Contato: https://libreplanet.org/wiki/User:Adfeno#vCard
- Arquivos comuns aceitos (apenas sem DRM): Corel Draw, Microsoft
  Office, MP3, MP4, WMA, WMV.
- Arquivos comuns aceitos e enviados: CSV, GNU Dia, GNU Emacs Org, GNU
  GIMP, Inkscape SVG, JPG, LibreOffice (padrão ODF), OGG, OPUS, PDF
  (apenas sem DRM), PNG, TXT, WEBM.


[Trisquel-users] Abrowser won't run Regexr

2017-11-24 Thread Caleb Herbert
I'm having issues running Regexr in Abrowser.

http://bluehome.net/csh/screenshot/2017/11/24/regexr

What could be going wrong?

Regexr is a free software web app for interactively exploring regular
expressions.


-- 
Caleb Herbert
OpenPGP public key: http://bluehome.net/csh/pubkey


signature.asc
Description: This is a digitally signed message part