Skip to main content
Update MATL Online URL
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52

MATL, 17 bytes

Yb94ih'(.*)'h6&XX

Try it on MATL OnlineTry it on MATL Online

How?

Yb - Split the input at spaces, place the results in a cell array

94 - ASCII code for ^ character

ih - Get the input (say "frac"), concatenate '^' and the input

'(.*)'h - Push the string '(.*)' into the stack, concatenate '^frac' and '(.*)'. So now we have '^frac(.*), a regex that matches "frac" at the beginning of the string and captures whatever comes after.

6&XX - Run regexp matching, with 6& specifying 'Tokens' mode i.e., the matched capture groups are returned instead of the entire match.

Implicitly output the results.

MATL, 17 bytes

Yb94ih'(.*)'h6&XX

Try it on MATL Online

How?

Yb - Split the input at spaces, place the results in a cell array

94 - ASCII code for ^ character

ih - Get the input (say "frac"), concatenate '^' and the input

'(.*)'h - Push the string '(.*)' into the stack, concatenate '^frac' and '(.*)'. So now we have '^frac(.*), a regex that matches "frac" at the beginning of the string and captures whatever comes after.

6&XX - Run regexp matching, with 6& specifying 'Tokens' mode i.e., the matched capture groups are returned instead of the entire match.

Implicitly output the results.

MATL, 17 bytes

Yb94ih'(.*)'h6&XX

Try it on MATL Online

How?

Yb - Split the input at spaces, place the results in a cell array

94 - ASCII code for ^ character

ih - Get the input (say "frac"), concatenate '^' and the input

'(.*)'h - Push the string '(.*)' into the stack, concatenate '^frac' and '(.*)'. So now we have '^frac(.*), a regex that matches "frac" at the beginning of the string and captures whatever comes after.

6&XX - Run regexp matching, with 6& specifying 'Tokens' mode i.e., the matched capture groups are returned instead of the entire match.

Implicitly output the results.

add explanation
Source Link
Sundar R
  • 6.6k
  • 19
  • 33

MATL, 17 bytes

Yb94ih'(.*)'h6&XX

Try it on MATL Online

How?

Yb - Split the input at spaces, place the results in a cell array

94 - ASCII code for ^ character

ih - Get the input (say "frac"), concatenate '^' and the input

'(.*)'h - Push the string '(.*)' into the stack, concatenate '^frac' and '(.*)'. So now we have '^frac(.*), a regex that matches "frac" at the beginning of the string and captures whatever comes after.

6&XX - Run regexp matching, with 6& specifying 'Tokens' mode i.e., the matched capture groups are returned instead of the entire match.

Implicitly output the results.

MATL, 17 bytes

Yb94ih'(.*)'h6&XX

Try it on MATL Online

MATL, 17 bytes

Yb94ih'(.*)'h6&XX

Try it on MATL Online

How?

Yb - Split the input at spaces, place the results in a cell array

94 - ASCII code for ^ character

ih - Get the input (say "frac"), concatenate '^' and the input

'(.*)'h - Push the string '(.*)' into the stack, concatenate '^frac' and '(.*)'. So now we have '^frac(.*), a regex that matches "frac" at the beginning of the string and captures whatever comes after.

6&XX - Run regexp matching, with 6& specifying 'Tokens' mode i.e., the matched capture groups are returned instead of the entire match.

Implicitly output the results.

deleted 164 characters in body
Source Link
Sundar R
  • 6.6k
  • 19
  • 33

MATL, 1417 bytes

Ybi'Yb94ih'(.*)'h6&XX

Try it on MATL Online

Nope, buggy, allows the "prefix" to be anywhere in the words. Fixing it...Try it on MATL Online

MATL, 14 bytes

Ybi'(.*)'h6&XX

Try it on MATL Online

Nope, buggy, allows the "prefix" to be anywhere in the words. Fixing it...

MATL, 17 bytes

Yb94ih'(.*)'h6&XX

Try it on MATL Online

Source Link
Sundar R
  • 6.6k
  • 19
  • 33
Loading