Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

Ruby flavor

Open achikin opened this issue 10 years ago • 24 comments

Please add ruby support.

achikin avatar Jun 17 '14 09:06 achikin

I'd love to, but I would need to look into a good way of doing this without incorporating a server..

firasdib avatar Jun 21 '14 15:06 firasdib

How do you currently do it with Python and PHP? Don't those need a server?

Ajedi32 avatar Jul 09 '14 17:07 Ajedi32

Maybe you could try compiling Rubinius's implementation of Regex with Opal?

Ajedi32 avatar Jul 09 '14 17:07 Ajedi32

Sorry, missed your reply @Ajedi32. Those libraries have been compiled into Javascript and run within your browser - thus making it responsive. I'm unsure if I could do the same with Ruby's regex engine. Kind of the same problem as with #54.

firasdib avatar Jul 22 '14 09:07 firasdib

@firasdib So do you think it would be feasible to compile Rubinius's implementation of Ruby's Regex library to JavaScript using Opal? That seems like it could work, at least in theory.

Ajedi32 avatar Jul 22 '14 13:07 Ajedi32

I don't have the time to fiddle with it right now, but you're free to. I would suspect Opal would use javascript regex implementation and not rubys own engine.

firasdib avatar Jul 22 '14 14:07 firasdib

@firasdib Yeah, Opal's native implementation of Regex does just use JavaScript's native Regex under the hood. That's why I recommended using Opal to compile Rubinius's implementation of Ruby's Regex library, which seems to be written in pure Ruby. Then you'd end up with a cross-compiled JavaScript version of Rubinius's regex library which you could run in the browser.

Maybe I'll look into this a bit deeper later. Really there's only so far I can go though without having access to Regex101's source (e.g. I can't do the final step of integrating my solution with Regex101 and sending a pull request).

Ajedi32 avatar Jul 22 '14 15:07 Ajedi32

Keep me posted! As long as you can get a basic working sample I can finish the rest.

firasdib avatar Jul 25 '14 21:07 firasdib

No idea how different Ruby's regex is. There is Rubular which is a browser based regex editor/tester. Not sure if it uses a server execution.

Ruby could be a solid addition since you already have python regex. I would have suggested it myself.

bryc avatar Aug 31 '14 02:08 bryc

@bryc Rubular runs server side, which is something I'm trying to avoid. I agree this would be a great addition, but I need to think of a good way of doing this.

firasdib avatar Aug 31 '14 09:08 firasdib

+1

stefanahman avatar Sep 03 '14 07:09 stefanahman

:+1: Waiting for Ruby support

jpalumickas avatar Nov 14 '14 11:11 jpalumickas

@firasdib I too would really love Ruby support, as while I use Rubular now, the explanations and match information on regex101 are really invaluable to someone like me learning several flavors at once.

Regarding running a Ruby engine server-side: feel free to email me privately if you want, but what sort of server specs would you need (processing capabilities, RAM, monthly data transfer amounts, disk space, etc.), or are you just not interested in a server-side approach at all? I ask because I'm a very happy customer of Webfaction, and I'd be willing to donate some space, or donate money to support a separate account (whatever would work best).

MattDMo avatar Sep 09 '15 22:09 MattDMo

:+1:

margaritis avatar Feb 12 '16 14:02 margaritis

:+1:

mrslain avatar Mar 20 '16 18:03 mrslain

The new release will feature a code generator for Ruby which might help some. The PCRE engine is still as close as you're going to get, which is likely going to cover it for most of your cases. But so far I have not been able to get the actual engine running. Sorry!

firasdib avatar Aug 22 '16 21:08 firasdib

👍

maxime-lenne avatar Nov 13 '18 13:11 maxime-lenne

This might be possible now with the emergence of WebAssembly. In fact, there's a project called ruby-wasm that can compile Ruby scripts into WebAssembly modules (technically, it actually compiles a minimal interpreter and embeds the script), and it even allows the use of some gems, such as mruby-onig-regexp, an MRuby version of the Onigmo regex library, the default regex library for Ruby 2.x.

The only issue is that you can't call from Ruby into JavaScript or JavaScript into Ruby, which unfortunately means it can't be used for this project yet. However, it is something to watch and probably the quickest and easiest way of implementing Ruby regexes client-side.

facekapow avatar Aug 25 '19 14:08 facekapow

I also found onigasm, which is Oniguruma compiled to WebAssembly, and that is in a usable state.

facekapow avatar Aug 25 '19 17:08 facekapow

This is the same method that is currently being tested for .NET flavour. If that goes well, maybe something similar could be done for Ruby.

Doqnach avatar Aug 26 '19 06:08 Doqnach

Has there been any advancements that will allow us to run the ruby regex engine using WASM? If someone can whip up an example and show me how to build it, I can add it to the website.

firasdib avatar Feb 13 '21 12:02 firasdib

This PR seems to address that point: https://github.com/k-takata/Onigmo/pull/153

Got it compiled with below

git clone [email protected]:interscript/Onigmo.git
cd Onigmo
git remote set-url origin [email protected]:k-takata/Onigmo.git
git fetch
git pull --no-commit
docker run --rm  -e BUILD="stdlib" -v $(pwd):/src emscripten/emsdk  bash -c "apt-get up
date; apt-get install wabt;bash build-wasm.sh"

Test import in node

cat << EOF > index.mjs
import * as M from '/onigmo.wasm'
console.log(M);
EOF
docker run --rm -v $(pwd)/onigmo.wasm:/onigmo.wasm -v $(pwd)/index.mjs:/index.mjs node
 --experimental-modules --experimental-wasm-modules index.mjs

Or in browser

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Onigmo WebAssembly Example</title>
  <script type="application/javascript">
    WebAssembly.instantiateStreaming(
      fetch('onigmo.wasm'), importObject).then(obj => {
        console.log(obj);
      })
  </script>
</head>

scodeman avatar Mar 25 '21 03:03 scodeman

@scodeman The PR looks stale, do you know if there is any progress?

Fwiw, Onigmo seems quite similar to PCRE.

firasdib avatar Feb 09 '22 16:02 firasdib

I just wanted to highlight that Ruby 3.2.0 will come with WASM / WASI support. I wrote an article (in french) talking about that. There are WebAssembly runtime for Ruby like wasmer-ruby. Some people already made Ruby in the browser projects using WASM like runrb.io (source) or try ruby. So maybe the better way would be to compile Ruby to webassembly?

noraj avatar Jul 02 '22 12:07 noraj