2023-05-25 17:47:19 +02:00
|
|
|
# Lösung: Reguläre Ausdrücke: Matching
|
2023-05-23 09:19:31 +02:00
|
|
|
|
2023-05-25 17:49:42 +02:00
|
|
|
|
|
|
|
```ruby
|
2023-05-25 17:47:19 +02:00
|
|
|
def reverser(s)
|
|
|
|
/(.*) (.*)/ =~ s
|
|
|
|
"#{$2} #{$1}"
|
|
|
|
end
|
|
|
|
|
|
|
|
puts reverser("Ruby Programmierer")
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternative Lösung:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
def reverser(s)
|
|
|
|
m = /(.*) (.*)/.match(s)
|
|
|
|
"#{m[2]} #{m[1]}"
|
|
|
|
end
|
|
|
|
|
|
|
|
puts reverser("Ruby Programmierer")
|
2023-05-23 09:19:31 +02:00
|
|
|
```
|