I see a lot of weird answers with regular expressions and attribute handling... Why? Joomla! has a great API in JForm to do everything you need. Since it's not quite clear what you want to accomplish I'll give you three alternatives for doing things the Joomla! Way.
If you want to remove a specific field from a form it's easy to do it if you know the name of the fieldset and the field.
If you want to get the names of all fields in a fieldset -- and possibly remove them from the form -- try:
$fields = $form->getFieldset('my_fieldset_name');
foreach ($fields as $field)
$name = $field->getAttribute('name');
// And possibly delete the field here:
// $form->removeField($name, 'my_fieldset_name');
However, this removes the fields, not the fieldset. If you want to remove an entire fieldset you just need to know that before Joomla! 1.6 they were called "groups", hence the surviving method being called removeGroup:
I recommend using an IDE such as PhpStorm or NetBeans and type hinting (in the form of
/** @var JForm $form */)to get autocompletion of the method names. In most IDEs you can CTRL-click (macOS: CMD-click) the method name to go into its declaration in Joomla's core to understand what it does. That's how I learned how Joomla works: following the code in an IDE. It's not magic, it's Open Source Software :)